简体   繁体   中英

iPhone presenting and dismissing navigation view controller in storyboards?

I have root view that presents navigation controller with content controller, this is how it looks like: 在此处输入图片说明

NavigationController is presented modally, and ProjectTypeSelectionView is his root controller. When tapping logout button i want to dismiss modal view and return to LoginScreenViewController.

So i set in prepareSegue LoginScreen as delegate:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

 UINavigationController *destination = segue.destinationViewController;

 if ([[destination ] respondsToSelector:@selector(setDelegate:)]) {
     NSLog(@"%@", destination);
     [destination setValue:self forKey:@"delegate"];
}
}

and then inside ProjectTypeViewController add this method:

 - (IBAction)logout:(id)sender {
      [self.delegate projectTypeSelectionViewControllerDidFinish];
 }

which is called when logout button is tapped. To my suprise this doesn't dismiss controller. Nothing happens, even thou everything is connected.

I have traced error to this - when prepareSegue is called NavigationController's delagate is set to LoginScreenViewController, insetad of setting ProjectTypeController's delegate to LoginScreenViewController.

How do i solve this properly?

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

 UINavigationController *destination = segue.destinationViewController;
UIViewController *vc = [[destination viewControllers] objectAtIndex:0];
vc.delegate = self;
}

To make this code more robust you might want to check if the desitinationViewController is a UINavigationController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM