我有一个3视图A B C,三个都有一个导航栏。我需要的是当我点击C视图后退按钮我要打开一个视图,但当我回到A时出现问题。在A的导航栏添加C后退按钮。
我试过这个
UIBarButtonItem * back=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(move)];
self.navigationItem.leftBarButtonItem=back;
-(void)move
{
FirstViewController * fvc=[[FirstViewController alloc]init];
[[self navigationController]pushViewController:fvc animated:NO];
}
请提前帮助我。
答案 0 :(得分:1)
View Controller被推入堆栈索引0,1,2,这意味着FirstViewController At 0 index,SecondViewController At 1 index。
所以你可以试试这个
[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:0] animated:YES];
0 index适用于您的第一视图控制器。
试试这个对你有帮助。
答案 1 :(得分:0)
UIBarButtonItem * back=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(move)];
self.navigationItem.leftBarButtonItem=back;
如果你想推进另一个视图控制器,那么使用这个
-(void)move
{
FirstViewController *fvc = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
[self.navigationController pushViewController:fvc animated:YES];
}
如果您想返回之前的屏幕,请使用此代码
-(void)move
{
[self.navigationController popViewControllerAnimated:YES];
}
答案 2 :(得分:0)
我认为你应该使用
[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:VCIndex] animated:YES]
答案 3 :(得分:0)
这一个
-(void)Back
{
NSArray *array1 = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array1 objectAtIndex:1] animated:YES];
// objectAtIndex put your as requirement like 0,1,2 etc..
}
答案 4 :(得分:0)
尝试
-(void)move
{
[navigationController popToRootViewControllerAnimated:YES];
}