简体   繁体   English

popToViewController无法在视图之间切换

[英]popToViewController can't switch between views

I have this function in an IBAction button: 我在IBAction按钮中具有此功能:

I start off with a table with a button, when that button is pressed this takes place: 我从一个带有按钮的表开始,当按下该按钮时,将发生以下情况:

TabBarController *v = [[TabBarController alloc] 
                          initWithNibName:@"TabBarController" bundle:nil];
[self.navigationController pushViewController: v animated:YES];
[v release];

On the second view there is another button which when pressed does this: 在第二个视图上,还有另一个按钮,按下该按钮即可:

NSArray *array = [self.navigationController viewControllers];

[self.navigationController 
    popToViewController:[array objectAtIndex:1] animated:YES];

This causes the app to crash, and at index 0 it does nothing. 这会导致应用程序崩溃,并且在索引0处它什么也不做。 Is this because the second page is not a UITable like the first? 这是因为第二个页面不是第一个页面的UITable吗?

I want to be able to move from UITable view to UIView back and forth, should I use addSubview instead? 我希望能够从UITable视图来回移动,应该使用addSubview代替吗? I need the first view to have a navbar but the second shouldn't. 我需要第一个视图具有导航栏,但第二个视图则不需要。

I think the problem is that [array objectAtIndex:1] is your current ViewController, so popping to the current view controller might be the reason of your crash (did not try it though) 我认为问题在于[array objectAtIndex:1]是您当前的ViewController,因此弹出当前视图控制器可能是导致崩溃的原因(尽管未尝试)

So why don't you do: 那么,为什么不这样做:

[self.navigationController popViewControllerAnimated:YES];

simply add the following line in button code and it will work fine 只需在按钮代码中添加以下行,它将正常工作

[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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