Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigate Back to previous view controller

I have a UIView->UICollectionView->UICollectionViewCell. I am trying to navigate back programatically but none of these works. The code did called. I am using StoryBoard.

- (void) goBack:(NSNotification *) notification {
      // [self.navigationController popViewControllerAnimated:YES];
     //  [self dismissViewControllerAnimated:YES completion:nil];
      [self.navigationController popToRootViewControllerAnimated:YES];
}
like image 803
user1688346 Avatar asked Apr 18 '13 05:04

user1688346


People also ask

How do I switch between view controllers?

Open object library (shift-command-L) and drag-drop two view controllers on storyboard.

How do I segue to another view controller?

Well, in addition to that, Ctrl+dragging also helps set up segues. So, Ctrl+Drag from the “Go to Other View Controller” button, to somewhere in the second View Controller. It can be anywhere in the main box of the second view controller. When you release, it will show you a box like the one below.


2 Answers

You need to use:

[self.navigationController popToRootViewControllerAnimated:YES];

This will bring you back to the root view controller.

If you want to navigate back to previous view controller, you should implement:

[self.navigationController popViewControllerAnimated:YES];
like image 181
Vineet Singh Avatar answered Oct 16 '22 13:10

Vineet Singh


By using below line we can go to parent view controller

[self.navigationController popViewControllerAnimated:YES]; 

By using below line we can move to main/root view controller

[self.navigationController popToRootViewControllerAnimated:YES]; 

By using below line we can move to any view controller

[self.navigationController popToViewController:viewControllerObject animated:YES]; 
like image 19
Madhu Avatar answered Oct 16 '22 13:10

Madhu