ios - segue 和 NavigationController 导航有什么问题

标签 ios objective-c uinavigationcontroller segue xcode5

这是该线程的延续/替代:popToRootViewControllerAnimated problem以更有条理和更容易理解的方式找出问题/错误是什么。

在 VC3 中按下后退按钮时,我想返回到 VC1。

我有以下设置:

enter image description here

以下代码:

VC1:

@implementation ViewController
- (IBAction)myButton1:(id)sender {

//Call InformationViewController for Quick Game
[self performSegueWithIdentifier:@"toVC2" sender:self];


}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

VC2:

@implementation nrTwoViewController
- (IBAction)myButton2:(id)sender {
//Call InformationViewController for Quick Game
[self performSegueWithIdentifier:@"toVC3" sender:self];

}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

VC3:

@implementation nrThreeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.


}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController popToRootViewControllerAnimated:YES];
}


@end

我只弹出到 VC2,而不是根目录 (VC1),并且在 VC3 上按返回按钮时收到以下消息:

2013-10-15 08:36:08.479 segueTest[44153:a0b] nested pop animation can result in corrupted navigation bar
2013-10-15 08:36:08.831 segueTest[44153:a0b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

我也按照建议尝试添加 UINavigationBarDelegate:

@interface nrThreeViewController : UIViewController <UINavigationBarDelegate>

...和:

- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
[self.navigationController popToRootViewControllerAnimated:YES];
return NO;
}

结果:

pop'ed from VC3 to VC2 only with no messages in the console.

最佳答案

问题是您放置 [self.navigationController popToRootViewControllerAnimated:YES]; 的错误消息是 Finishing up a navigation transition in an unexpected state. 这是因为当调用 viewWillDisappear 时, View 已经开始从屏幕上过渡,然后您将调用另一个过渡。尝试将它放在一个简单地弹出到 Root View Controller 的按钮操作中,看看是否能解决您的问题。

关于ios - segue 和 NavigationController 导航有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19375049/

相关文章:

ios - 从 CCLayer 做 Storyboard segue

ios - 使用多个按钮从屏幕继续?

ios - 如何在应用程序进入前台之前准备 UI 更新

使用 UIImagePickerController/ImagePicker 的 iOS Swift 和 Xamarin 应用程序崩溃

ios - 设置特定的 UITableView 行以推送到特定的详细信息 View 中?

iOS,应该如何备份导航堆栈而不是root?

ios - 如何使用 SlideMenuViewcontroller 从 Mainviewcontroller 导航到另一个 View Controller

iphone - 如何解析 XML 的多个属性?

iOS GL ES 2 应用程序在设备上崩溃但在模拟器上不崩溃

objective-c - 为什么iOS模拟器会对此暂停?