Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing a view displayed via a modal segue

I'm manually invoking a segue (set as modal) in order to display a login form in Xcode 4.2 using Storyboards with the following line of code:

[self performSegueWithIdentifier:@"LoginSegue" sender:nil];

I'm probably missing something really simple, however I can't find a way to programmatically close the login view and return to the previous view.

The view is part of a navigation view controller, so setting the segue type to "push" allows me to use the back button to send me back to my previous screen, but in "modal" mode, I'm not entirely sure how to achieve this (after button press, for example)

Any help would be much appreciated.

like image 559
Nick Avatar asked Dec 14 '11 23:12

Nick


2 Answers

If your deployment target is iOS 5.0 or later, use this message:

[self dismissViewControllerAnimated:YES completion:nil];

Or in Swift:

self.dismissViewControllerAnimated(true, completion: nil)

If your deployment target is older, use this (deprecated) message:

[self dismissModalViewControllerAnimated:YES];
like image 150
rob mayoff Avatar answered Nov 09 '22 19:11

rob mayoff


[self dismissViewControllerAnimated:YES completion:nil]; is a new way in IOS5

like image 13
denny Avatar answered Nov 09 '22 17:11

denny