【发布时间】:2018-02-18 04:15:12
【问题描述】:
我有三个视图控制器:ViewControllerA、ViewControllerB 和 ViewControllerC。
当我在ViewControllerC时,点击导航Back按钮直接回到ViewControllerA,跳过ViewControllerB。
我尝试了以下方法,它们都有效。但是,我想知道在从 ViewController C 过渡到 ViewController A 时,它会在一秒钟内显示 ViewController B 在过渡期间。
有没有办法直接从 ViewController C 导航到 ViewController A 跳过 ViewControllerB。
方法一:
-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
NSLog(@"back button pressed");
[self.navigationController popViewControllerAnimated:YES];
}
[super viewWillDisappear:animated];
}
方法2:
-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
NSLog(@"back button pressed");
//[self.navigationController popViewControllerAnimated:YES];
NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]];
for (UIViewController *aViewController in allViewControllers) {
if ([aViewController isKindOfClass:[ViewControllerA class]]) {
[self.navigationController popToViewController:aViewController animated:NO];
}
}
}
[super viewWillDisappear:animated];
}
【问题讨论】:
-
你听说过 Unwind Segue 吗?如果您使用故事板,请通过this
-
[self.navigationController popToRootViewControllerAnimated:YES];
-
你能显示你的后退按钮代码吗?
-
我正在使用导航返回按钮项。
-
不,抱歉,我现在就回答,这是一个常见问题
标签: ios objective-c uinavigationcontroller navigation