gpt4 book ai didi

ios - 导航返回显示过渡期间的其他Viewcontroller

转载 作者:行者123 更新时间:2023-12-01 19:45:26 24 4
gpt4 key购买 nike

我有三个Viewcontroller:ViewControllerA,ViewControllerB和ViewControllerC。

当我在 ViewControllerC 中时,我单击Navigation Back 按钮直接返回ViewControllerA,而跳过 ViewControllerB

我尝试了以下方法,它们都有效。但是,我想知道从ViewController C过渡到ViewController A时,它在过渡期间在一秒钟内显示了ViewControllerB。

有没有一种方法可以直接从ViewController C导航到ViewController A,从而跳过ViewControllerB。

方法1:

-(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];
}

最佳答案

您需要使用setViewControllers方法,并仅传递作为navigationController.viewControllers数组中第一个元素的viewControllerA

代码

- (IBAction)backAction:(id)sender {
UIViewController * viewControllerA = [self.navigationController.viewControllers firstObject]; //we get the first viewController here
[self.navigationController setViewControllers:@[viewControllerA] animated:YES];
}

类似的答案在这里 How to start from a non-initial NavigationController scene但很快

enter image description here

关于ios - 导航返回显示过渡期间的其他Viewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48848383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com