Это продолжение/альтернатива этой темы: popToRootViewControllerAnimated problem, чтобы разобраться, в чем проблема/ошибка в более структурированном и понятном для понимания способом.Что происходит с навигацией segue и NavigationController
При нажатии кнопки «Назад» в 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;
}
Результат:
pop'ed от VC3 до VC2 только без каких-либо сообщений в консоли.
спасибо за ваш комментарий, это действительно решение. Подробнее о том, как это сделать здесь: http://stackoverflow.com/questions/19365260/self-navigationcontroller-poptorootviewcontrolleranimatedyes-do-not-pop-back-to – PeterK