72nd Day As An iOS Developer With No Experience

December 10, 2015 - 72nd Day As An iOS Developer With No Experience

Last time I mentioned that there is a big help for me - Sir P. Our part time senior iOS Developer. He has taught me many stuffs in iOS programming. I am glad he came to the company. I have here a very quick and short tutorial. How to present a view controller from a presented view controller.

Ok, I'll repeat the title of this quick tutorial.

PRESENTING VIEWCONTROLLER FROM A CURRENTLY PRESENTED VIEWCONTROLLER.

Check out this code first before I explain it:

                              UpgradePremiumViewController *upgradeVC = [UpgradePremiumViewController new];
                              AVNavigationController *uiNav = [[AVNavigationController alloc] initWithRootViewController:upgradeVC];
                            
                              uiNav.navigationBar.topItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"NYTPhotoViewerCloseButtonX"] landscapeImagePhone:[UIImage imageNamed:@"NYTPhotoViewerCloseButtonXLandscape"] style:UIBarButtonItemStylePlain target:self action:@selector(doneButtonTapped:)];

                              [self presentViewController:uiNav animated:YES completion:nil];
Take note that the code above is just an example. You can't just copy and paste it, you have to edit it first.

So I have here the UpgradePremiumViewController, this is the ViewController that I will be presenting from a presented view controller. So I instantiate it, there I have the upgradeVC instance variable.

Then I will have a UINavigationController (take note again that I have here a different kind of UINavigationController, but technically they're the same). So I now have the uiNav instance with RootViewController: upgradeVC.

After all of these steps, we can now present the navigation controller uiNav. We can even modify its navigationbar.

There you go my readers. If I helped you, please subscribe and share.

Post a Comment