
This video is only available to subscribers. Start a subscription today to get access to this and 469 other videos.
Handling the Photo Transition
This episode is part of a series: Refactoring to Coordinators.
1. Why Coordinators? 15 min |
2. Handling Actions from Users 11 min |
3. Moving Review Logic 17 min |
4. Handling the Photo Transition 8 min |
Episode Links
- Source Code
- Patterns of Enterprise Application Architecture - This book covers many software architecture patterns, but the _App Controller
Adding the Photos Transition
The first step is to remove the segue. Then we can add a new method to our RestaurantViewControllerDelegate
protocol to be called when the user taps on the photos cell:
protocol RestaurantViewControllerDelegate : class {
func addReviewTapped(_ vc: RestaurantViewController)
func photosTapped(_ vc: RestaurantViewController)
}
We need to call this when the user taps on that cell, but that was previously done by the storyboard directly. We need to handle this action manually now:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == Sections.info.rawValue && indexPath.row == 1 {
restaurantDelegate?.photosTapped(self)
} else {
// nada
}
}
Add Conformance to AppCoordinator
We added a method to the protocol, so we need to update our coordinator to implement this method.
func photosTapped(_ vc: RestaurantViewController) {
let photosVC = PhotosViewController.makeFromStoryboard()
photosVC.restaurantID = vc.restaurantID
navigationController.pushViewController(photosVC, animated: true)
}