ingh.am
ingh.am

Reputation: 26742

Simulating the back button on the UINavigationController on the iPhone

I currently have a TableView inside a NavigationController where when a item is selected the following code is ran:

DetailViewController *DetailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];

[self.navigationController pushViewController:DetailViewController animated:YES];
[DetailViewController release];
DetailViewController = nil;

This loads up my detail view, however my question is this... How can I call the backbutton on the navigation controller without pressing it? Or how can set it back to the table view (which is what the backbutton does)?

Thanks for any help :)

Upvotes: 10

Views: 9997

Answers (2)

Yaron Abramovich
Yaron Abramovich

Reputation: 91

In Swift:

navigationController?.popViewController(animated: true)

Upvotes: 0

Philippe Leybaert
Philippe Leybaert

Reputation: 171744

You can call the popViewController method:

[self.navigationController popViewControllerAnimated:YES];

Upvotes: 38

Related Questions