My Secondview is B开发者_如何学GoController *bview. now in this view there is 1 back button
on click of that back button
-(IBAction)done:(id)sender
{
AController *aview= [[AController alloc] initWithNibName:@"AController" bundle:[NSBundle mainBundle]];
NSArray *array = [self.navigationController popToViewController: aview animated:YES];
}
AController *aview is nothing but my first view or you can say first view
but in click of back button I'm getting exception
** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.' 2010-03-18 15:53:05.948 IChitMe[5072:207] Stack: ( 820145437, 837578260, 819694387, 814928571, 862794500, 862794216, 54911, 819902607, 861951876, 862404412, 819902607, 861951876, 861951724, 861951668, 861950732, 861953932, 861948160, 861945748, 861927312, 861925524, 858687888, 819893547, 819891231, 858682228, 861592624, 861585968, 10069, 9964 ) terminate called after throwing an instance of 'NSException'
Use
[self.navigationController popViewControllerAnimated:YES];
OR
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
navigationController manages stack of UIViewControllers. It's like stack of cards. When you call one of pop methods:
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
you remove some controllers from top, and show corresponding controller:
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
pops to first (i.e. lowest in stack) controller, it is called "root".
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
pops to specified viewController, and note it should be already in the stack!
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
pops to previous controller (below current).
So if you want to show your AController *aview using pop... method of navigationController it should be already in navigationController stack - this is viewControllers property of navigationController:
@property(nonatomic, copy) NSArray *viewControllers
for example:
aController = [[AController alloc] initWithNibName:@"AController" bundle:[NSBundle mainBundle]];
bController = [[BController alloc] initWithNibName:@"BController" bundle:[NSBundle mainBundle]];
navigationController = [[UINavigationController alloc] initWithRootViewController:aController];
[navigationController pushViewController:bController];
now bController is shown and you can call:
[navigationController popToViewController:aController animated:YES];
精彩评论