segue和NavigationController导航有什么问题

时间:2013-10-15 06:59:47

标签: 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;
}

结果:

  

从VC3弹出到VC2,但控制台中没有消息。

1 个答案:

答案 0 :(得分:1)

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