我有3个视图控制器(VC)AB C.首先我呈现A.然后我推B,然后推C.当我推C后,我从堆栈中删除B,所以如果用户按下返回键。我用这个代码推C和删除B:Uinavigationitem后退按钮不可见,直到我点击导航的左侧。 bar
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Nazaj" style:UIBarButtonItemStylePlain target:nil action:nil];
//we push C
PorabaControllerR *anotherViewController = [[PorabaControllerR alloc] initWithNibName:@"PorabaViewR" bundle:nil];
//[anotherViewController setTitle:@"Pregled porabe"];
[anotherViewController.navigationItem setBackBarButtonItem:backButton];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
//we remove B from the stack
NSMutableArray *allControllers = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
[allControllers removeObjectAtIndex:[allControllers count] - 2];
//[allControllers objectAtIndex:[allControllers count] - 2]
[self.navigationController setViewControllers:allControllers animated:NO];
[allControllers release];
问题是,uinav。项目的后退按钮不会显示在C上,直到我走到它上面并点击它。 (在B上是OK)。 如何在执行过程中调试它或者观看按钮标题更改有没有什么好方法? 有没有其他想法?
编辑:我试着用维杰的想法:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Nazaj" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonClick:)];
-(IBAction)leftBarButtonClick:(UIButton *) sender {
NSLog(@"clicked left");
//back to home screen
[self.navigationController popToRootViewControllerAnimated:YES];
}
,但此功能未在所有打来电话,后退按钮仍然隐藏,直到我走了过来,并点击它。