etab
etab

Reputation: 199

adding Cancel UIButton to UINavigation controller

I am using storyboard, I added a navigation bar to a view controller and i added two bar buttons (in storyboard not code) to the navigation bar, one is "save" button and the other is "cancel" button.

now i want when i press the cancel button the already viewed controller to disappear and the previous view controller to show up. what is the code i should include in the action method of the cancel button :

- (IBAction)cancel:(id)sender 
{
    // what code should be written here ?
}

Upvotes: 2

Views: 59

Answers (1)

Mick MacCallum
Mick MacCallum

Reputation: 130222

That depends on how you presented the view controller in the first place. If you presented it modally, then you would use this:

[self dismissViewControllerAnimated:YES completion:nil];

However, if you pushed to the current view controller via navigation controller, then you would use this:

[self.navigationController popViewControllerAnimated:YES];

Upvotes: 4

Related Questions