[英]iOS: Custom back button doesn't work
我在項目中使用FlatUIKit。 我有一個定義的自定義“后退”按鈕,如下所示:
[UIBarButtonItem configureFlatButtonsWithColor:[UIColor peterRiverColor]
highlightedColor:[UIColor belizeHoleColor]
cornerRadius:3
whenContainedIn:[UINavigationBar class], nil];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStylePlain
target:self
action:@selector(clickBack)];
這是我的clickBack
-(void)clickBack{
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-1] animated:YES];
}
該按鈕隨我所願顯示,僅此而已。 如果我單擊它,什么也不會發生。
知道我做錯了什么嗎? 我對此很陌生,從未更換后退按鈕。
您只是在您的評論之一中提到過,您以模態展示了視圖控制器,這是不同的。 您將要釋放模式視圖控制器。 嘗試這個:
[self dismissModalViewControllerAnimated:YES];
僅當要釋放的視圖被推到導航控制器上時,pop方法才起作用。
這是模態視圖控制器示例的鏈接。
http://timneill.net/2010/09/modal-view-controller-example-part-1/
在clickBack方法中使用此代碼
[self.navigationController popViewControllerAnimated:YES];
[UIBarButtonItem configureFlatButtonsWithColor:[UIColor peterRiverColor]
highlightedColor:[UIColor belizeHoleColor]
cornerRadius:3
whenContainedIn:[UINavigationBar class], nil];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStylePlain
target:self
action:@selector(clickBack)];
-(void)clickBack
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
照原樣復制並粘貼此代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.