Meg*_*anX 1 iphone uinavigationcontroller presentmodalviewcontroller uistoryboard
我有根视图,它提供了带有内容控制器的导航控制器,它的外观如下:

NavigationController以模态方式呈现,ProjectTypeSelectionView是其根控制器.当点击注销按钮时,我想解除模态视图并返回到LoginScreenViewController.
所以我在prepareSegue LoginScreen中设置为委托:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UINavigationController *destination = segue.destinationViewController;
if ([[destination ] respondsToSelector:@selector(setDelegate:)]) {
NSLog(@"%@", destination);
[destination setValue:self forKey:@"delegate"];
}
}
Run Code Online (Sandbox Code Playgroud)
然后在ProjectTypeViewController中添加此方法:
- (IBAction)logout:(id)sender {
[self.delegate projectTypeSelectionViewControllerDidFinish];
}
Run Code Online (Sandbox Code Playgroud)
点击注销按钮时调用.令我惊讶的是,这并没有解雇控制器.没有任何事情发生,即使你的一切都是连通的.
我已经跟踪了错误 - 当prepareSegue被调用时,NavigationController的delagate被设置为LoginScreenViewController,将ProjectTypeController的委托设置为LoginScreenViewController的插件.
我该如何正确解决这个问题?
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UINavigationController *destination = segue.destinationViewController;
UIViewController *vc = [[destination viewControllers] objectAtIndex:0];
vc.delegate = self;
}
Run Code Online (Sandbox Code Playgroud)
为了使这段代码更加健壮,您可能需要检查desitinationViewController是否是UINavigationController
| 归档时间: |
|
| 查看次数: |
1808 次 |
| 最近记录: |