Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS equivalent of Android finish()

I am relatively new to iOS development. I developed an app for Android first, and now am porting it to iOS. One thing that I can't figure out is how to make a ViewController "go away". I'm accustomed to the finish() method in Android. With that method, the current activity ends itself and the user is presented with the the previous screen that was open prior to opening the current screen.

What I'm trying to accomplish is making my "create" screen go away after a record is saved. In the Android world, I would just call the finish() method and that would be taken care of. What is the iOS equivalent?

I have tried the following code in my iOS app, hoping that the view would be animated away.

[self.navigationController popToRootViewControllerAnimated:YES];

Edit: The view was presented as below.

SettingsViewController *vc = [[SettingsViewController alloc] initWithNibName:@"SettingsView"]; 
controllers = [NSArray arrayWithObject:vc];
self.sideMenu.navigationController.viewControllers = controllers;
[self.sideMenu setMenuState:MFSideMenuStateClosed];

where controllers is defined as such:

NSArray *controllers = nil;
like image 296
acedanger Avatar asked Apr 06 '13 18:04

acedanger


1 Answers

How did you present this view controller?

Did you use presentViewController:animated:completion:? If so, you want something like this:

[self dismissViewControllerAnimated: YES];

If you are using pushViewController:animated:, you are not talking about a modal view. You are talking about a normal ViewController you pushed onto the stack. To "undo" this, you need to pop the view controller:

[self.navigationController popViewControllerAnimated: YES];
like image 94
Alec Gorge Avatar answered Nov 14 '22 08:11

Alec Gorge