我有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];
}
,但此功能未在所有打來電話,後退按鈕仍然隱藏,直到我走了過來,並點擊它。