How to Navigate from one View Controller to another using Swift

Create a swift file (SecondViewController.swift) for the second view controller and in the appropriate function type this: let secondViewController = self.storyboard.instantiateViewControllerWithIdentifier(“SecondViewController”) as SecondViewController self.navigationController.pushViewController(secondViewController, animated: true) Swift 2+ let mapViewControllerObj = self.storyboard?.instantiateViewControllerWithIdentifier(“MapViewControllerIdentifier”) as? MapViewController self.navigationController?.pushViewController(mapViewControllerObj!, animated: true) Swift 4 let vc = UIStoryboard.init(name: “Main”, bundle: Bundle.main).instantiateViewController(withIdentifier: “IKDetailVC”) as? IKDetailVC self.navigationController?.pushViewController(vc!, animated: true)

Removing viewcontrollers from navigation stack

Use this code and enjoy: NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers]; // [navigationArray removeAllObjects]; // This is just for remove all view controller from navigation stack. [navigationArray removeObjectAtIndex: 2]; // You can pass your index here self.navigationController.viewControllers = navigationArray; [navigationArray release]; Hope this will help you. Edit: Swift Code guard let navigationController = self.navigationController … Read more

How to implement tab bar controller with navigation controller in right way

Hi you need to embed each view controller that is within the tab bar in a navigation controller of its own. So the flow is like so (HomeVC is embedded in a NavController of it’s own): / –> `NavController` –> `ViewController1` | –> `NavController` –> `ViewController2` `HomeViewController`–>`TabBarController`|–> `NavController` –> `ViewController3` \–> `NavController` –> `ViewController4` Go … Read more

Popover with embedded navigation controller doesn’t respect size on back nav

I was struggling with the same issue. None of the above solutions worked for me pretty nicely, that is why I decided to do a little investigation and find out how this works. This is what I discovered: When you set the contentSizeForViewInPopover in your view controller it won’t be changed by the popover itself … Read more

Changing back button in iOS 7 disables swipe to navigate back

IMPORTANT: This is a hack. I would recommend taking a look at this answer. Calling the following line after assigning the leftBarButtonItem worked for me: self.navigationController.interactivePopGestureRecognizer.delegate = self; Edit: This does not work if called in init methods. It should be called in viewDidLoad or similar methods.

UINavigationBar Hide back Button Text

In the interface builder, you can select the navigation item of the previous controller and change the Back Button string to what you’d like the back button to appear as. If you want it blank, for example, just put a space. You can also change it with this line of code: [self.navigationItem.backBarButtonItem setTitle:@”Title here”]; Or … Read more

Custom Animation for Pushing a UIViewController

I use the following function (added to UINavigationController) to customize the push animation: – (void) pushController: (UIViewController*) controller withTransition: (UIViewAnimationTransition) transition { [UIView beginAnimations:nil context:NULL]; [self pushViewController:controller animated:NO]; [UIView setAnimationDuration:.5]; [UIView setAnimationBeginsFromCurrentState:YES]; [UIView setAnimationTransition:transition forView:self.view cache:YES]; [UIView commitAnimations]; } I guess you could adapt this code to do whatever animation you want.

Trying to handle “back” navigation button action in iOS

Try this code using VIewWillDisappear method to detect the press of The back button of NavigationItem: -(void) viewWillDisappear:(BOOL)animated { if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) { // Navigation button was pressed. Do some stuff [self.navigationController popViewControllerAnimated:NO]; } [super viewWillDisappear:animated]; } OR There is another way to get Action of the Navigation BAck button. Create Custom button for UINavigationItem … Read more