In this lesson, let's reuse our UIPageViewController which will allow for faster image loads in our cards. This is a great solution because UIPageViewController does preloading for images in view controllers that are off screen. Let's refactor out our SwipingPhotosController such that we can support two different modes: Card View Mode and User Details Mode. Once we can support these two modes, we'll implement the fixes for certain bugs that will pop up.

Comments (7)
st4n
4 years ago
very nice :) i'm feeling that we commented out all the sdWebImage placeholder calls anyway :) a few issues thou: 1. when saving user profile with less than 3 photos, we are saving imgUrl2 and 3 with empty String "", which is generating extra bars and "empty swipes" 2. please bring back the pagination. 3. at the beginning of this entire course, we created advertiser cards. How to use them now? 4. in userDetailView, when you rotate the device there is no way back (other than un-rotate) :) maybe we could disable rotation i certain screens?
Brian Voong
4 years ago
slcott
4 years ago
Sharing my version of Brian's solution for changing the indicator bars after a tap: ``` if let index = controllers.firstIndex(of: currentController) { let tapLocation = gesture.location(in: view) let delta = tapLocation.x > view.frame.width / 2 ? 1 : -1 let nextIndex = max(0, min(controllers.count - 1, index + delta)) if index == nextIndex { return } let nextController = controllers[nextIndex] let direction: NavigationDirection = delta == 1 ? .forward : .reverse delegate?.pageViewController?(self, willTransitionTo: [nextController]) setViewControllers([nextController], direction: direction, animated: true) { (done) in if not(done) { return } self.delegate?.pageViewController?(self, didFinishAnimating: true, previousViewControllers: self.controllers, transitionCompleted: done) } } ``` The big difference is that my version calls two methods on the `UIPageViewControllerDelegate` which just so happens to be `self` (`delegate = self`) , thus avoiding the copy/paste.
Dennisvm82
4 years ago
Great job! Thanks for sharing. Learning a lot from you guys as well :-)
Christophe Bugnon
4 years ago
For those who got white screen on user because you got empty String, you can use this for create your array of imageUrls: let imageUrls = [model.imageUrl1, model.imageUrl2, model.imageUrl3].compactMap { $0 }.filter { $0.isEmpty == false }
flashtrend
4 years ago
Hi Brian how could we go about adding the "Like" and "Dislike" icon to the top corners of the cards as a user is swiping?
Tube
4 years ago
I think you should warn your millennial students when their safe space is going to be violated with a trigger word like "mode". ;-)
Cinquain
4 years ago
That video was fire!
David Guarino
4 years ago
I just started to laugh because of the flashing of cards in the background.....Could be a great subliminal advertising technique to get users to buy whatever the owner wants to sell them!
HELP & SUPPORT