I run into a weird issue.
When setting navigationController.viewControllers
to a new array whose viewControllers
equal to the current UIViewController.viewControllers
, then trying to segue to a new viewController
(push segue), the UIViewController.viewControllers
is messed up.
To be exact, I did the following:
-(void)viewWillAppear:(BOOL)animated
{
...
for(int i=0; i<[self.navigationController.viewControllers count]; i++)
{
NSLog(@"Befor: %d: %@",i, [[self.navigationController.viewControllers objectAtIndex:i] description]);
}
[[self navigationController] setViewControllers:[NSArray arrayWithObjects:[self.navigationController.viewControllers objectAtIndex:0], self,nil] animated:NO];
NSLog(@"After: Num of view controllers: %d", [self.navigationController.viewControllers count]);
for(int i=0; i<[self.navigationController.viewControllers count]; i++)
{
NSLog(@"After: %d: %@",i, [[self.navigationController.viewControllers objectAtIndex:i] description]);
}
}
Log results:
Befor: Num of view controllers: 2 2014-02-15 17:15:01.144[827:60b] Befor: 0: 2014-02-15 17:15:01.145[827:60b] Befor: 1: 2014-02-15 17:15:01.147[827:60b] After: Num of view controllers: 2 2014-02-15 17:15:01.148[827:60b] After: 0: 2014-02-15 17:15:01.149[827:60b] After: 1:
Then I pushed a button that segues to another viewController. Just before the segue this code called:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(@"prepareForSegue: Num of view controllers: %d", [self.navigationController.viewControllers count]);
for(int i=0; i<[self.navigationController.viewControllers count]; i++)
{
NSLog(@"prepareForSegue: %d: %@",i, [[self.navigationController.viewControllers objectAtIndex:i] description]);
}
...
}
Log results:
2014-02-15 17:15:05.388[827:60b] prepareForSegue: Num of view controllers: 1 2014-02-15 17:15:05.389[827:60b] prepareForSegue: 0:
I monitored the navigationController.viewControllers
at the destination viewController
and it seems that the rootViewController
vanished.
When trying to go back (using the navigation controller back button), things got ugly.
I noticed that all this stuff doesn't happen when I assign an array whose objects are different from the current navigationController.viewControllers
, so it's a workaround for now.
Did I do something wrong?