Last active
May 2, 2020 23:31
-
-
Save jamesrochabrun/130536b468b0a7978db2699307c99942 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In UserProfileViewController (the master) we need: | |
// 1 | |
protocol UserProfileFeedSelectionDelegate: AnyObject { | |
func postSelectedAt(_ indexPath: IndexPath) | |
} | |
// 2 | |
weak var delegate: UserProfileFeedSelectionDelegate? | |
// 3 | |
lazy private var contentDetailViewController: ContentDetailViewcontroller = { | |
let detailViewController = ContentDetailViewcontroller.instantiate(from: "Main") | |
delegate = detailViewController | |
return detailViewController | |
}() | |
extension UserProfileViewController: GridCollectionViewDelegate { | |
func cellDidSelect(_ indexPath: IndexPath) { | |
// 4 | |
guard let secondaryContentNavigationController = splitViewController?.secondaryViewController as? NavigationController, | |
let secondaryContentViewController = secondaryContentNavigationController.topViewController as? ContentDetailViewcontroller | |
else { | |
// 5 | |
let detailNavigationController = NavigationController(rootViewController: contentDetailViewController) | |
splitViewController?.showDetailInNavigationControllerIfNeeded(detailNavigationController, sender: self) | |
delegate?.postSelectedAt(indexPath) | |
return | |
} | |
// 6 | |
splitViewController?.showDetailInNavigationControllerIfNeeded(secondaryContentViewController, sender: self) | |
delegate?.postSelectedAt(indexPath) | |
} | |
} | |
// In ContentDetailViewcontroller (the detail) we need: | |
extension ContentDetailViewcontroller: UserProfileFeedSelectionDelegate { | |
// 7 | |
func postSelectedAt(_ indexPath: IndexPath) { | |
verticalFeedTableView?.scrollTo(indexPath, animated: true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment