THURSDAY - I love Thursdays, why you ask? Because it is near to Friday. Haha! I had a great day today, I fixed several tickets for my first ever project that is already on AppStore. Client just needs bug fixes so I'm back to it again. I just allocated like 4 hours of my time today.
I appreciate the PHAsset so much than the ALAsset of iOS. With PHAsset, I can do anything I want in a certain asset (video or photo). Anyway, I would like to share a quick knowledge that I've learned today. How to pop your navigation controller into a certain view controller?
Let me first discuss something short. There are three ways how to pop a view controller.
1. popToRootViewControllerAnimated
2. popViewControllerAnimated
3. popToViewController
The first one (popToRootViewControllerAnimated ) pops until there's only a single view controller left on the stack. Returns the popped controllers.
Below is the code:
- (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;You can use it like this:
[self.navigationController popToRootViewControllerAnimated:YES];
Next, we have the popViewControllerAnimated. Below is the code. This code below returns the popped controller. It will basically pop the very view controller that is below your current view controller. For instance, you have a main login screen. After pressing a button, there will be another screen (we'll call that screen as Screen2) Inside that Screen2, we have another button, we click that button and there will be a Screen3. In that Screen3, we have a close button (X). If we click that X button, we will be returned to Screen2. How to do that? Use the code below.
- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated;You can use the code above like this:
[self.navigationController popViewControllerAnimated:YES];
Last, the one that I've learned for today: the popToViewController. This will let us pop to a certain/specific view controller. As long as that view controller is listed in the array of presented view controllers. Below is the code:
- (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated;
Apple documentation describes the code above as:
Pops until there's only a single view controller left on the stack. Returns the popped controllers.
Great! You can use that code above like this:
[self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];You need to pass your specific view controller to that method. That's all for now. If you learned something here, subscribe and share! :)
Post a Comment