繁体   English   中英

segue和NavigationController导航有什么问题

[英]What is wrong with the segue and NavigationController navigation

这是该线程的延续/替代: popToRootViewControllerAnimated问题 ,它以更结构化和更易于理解的方式整理出问题/错误所在。

在VC3中按返回按钮时,我想返回VC1。

我有以下设置:

在此处输入图片说明

如下代码:

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

结果:

仅在控制台中没有消息的情况下从VC3弹出到VC2。

问题是您将[self.navigationController popToRootViewControllerAnimated:YES];放在哪里[self.navigationController popToRootViewControllerAnimated:YES]; 错误消息是Finishing up a navigation transition in an unexpected state. 这是因为调用viewWillDisappear时,视图已经开始在屏幕外过渡,然后您在调用另一个过渡。 尝试将其置于仅弹出到根视图控制器的按钮操作中,看看是否可以解决您的问题。

暂无
暂无

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

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