Search code examples
iosobjective-cuinavigationcontrollerdismissviewcontroller

Difference between `present` & `push` ViewController


dismissViewController method not working to get previous viewcontoller

[self.navigationController dismissViewControllerAnimated:YES completion:nil];

popViewController work and go to previous viewcontroller

[self.navigationController popViewControllerAnimated:YES];

i want to pass data like below please help me.but as i describe dismissViewController method not working.

 [self.navigationController dismissViewControllerAnimated:YES completion:^{
            HomeVC *loading;
            loading.IdNameLabel.text=display;
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Code" message:display delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
 }];

thank in advance.

Update

-(void)viewWillAppear:(BOOL)animated{
    self.IdNameLabel.text=self.GetscanResult;
}

this method contain in HomeVC.when dismiss navcontroller it shows HomeVC.

is upper method can call after dismiss viewcontroller?

SOLUTION

this is very stupid question when i am at beginner level. here is specification about it. it will depend on method which will you Present || Push viewController.

Delegate methods will work with protocol delegate method when view controller present.


Solution

  • The method you need to use to go back depends on how you showed the view controller.

    The first of the two common ways are by using a navigation view controller to push and pop view controllers off the stack.

    The other common way is to present and dismiss a view controller modally.

    You cannot for example present a view controller modally, and expect to be able to pop it off from the navigation controller, or vice versa.