Closing a view displayed via a modal segue

Objective CIosCocoa TouchUistoryboard

Objective C Problem Overview


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.

Objective C Solutions


Solution 1 - Objective C

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];

Solution 2 - Objective C

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

Solution 3 - Objective C

The following should work fine...

[self dismissModalViewControllerAnimated:YES];

I do exactly this with a login page in my latest tutorial here, with no issues.

Solution 4 - Objective C

The following code works in swift 3:

 self.dismiss(animated: true, completion: nil)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNickView Question on Stackoverflow
Solution 1 - Objective Crob mayoffView Answer on Stackoverflow
Solution 2 - Objective CdennyView Answer on Stackoverflow
Solution 3 - Objective CSimonView Answer on Stackoverflow
Solution 4 - Objective CBogdan RazvanView Answer on Stackoverflow