UIBarButton不會在我的UINavigationController中顯示 [英] UIBarButton won't show in my UINavigationController
本文介紹了UIBarButton不會在我的UINavigationController中顯示的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想創建一個帶有導航欄和表視圖的簡單視圖。所以我創建了UINavigationController
的一個子類,并在其中添加了一個UITableView
。我的IS也是UITableViewDataSource
和UITableViewDelegate
?,F在我想在導航欄中添加UIBarButton
,但它不起作用:
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:[[Translator instance] getTranslation:@"Back"]
style:UIBarButtonItemStylePlain
target:self.parentViewController
action:@selector(dismissFiltersModal:)];
self.navigationItem.backBarButtonItem = anotherButton;
沒有錯誤地顯示了視圖,但沒有顯示按鈕。我如何才能顯示它?
推薦答案
jafar,
正如Apple文檔建議您應避免子類UINavigationController
。
此類不用于子類化。
說到這里,你可以遵循這些簡單的步驟(給你的一些建議):
- 創建擴展
UIViewController
的控制器(比如MyController
),并在此處添加表格。將您的控制器設置為該表的代理和數據源。如果您是由XIB創建的,則需要為您的表視圖提供插座。
[P.S。您還可以子類化aUITableViewController
,它有自己的表視圖]
- 在
MyController
的viewDidLoad
中自定義導航欄。
例如
UIBarButtonItem* myButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(someSelector)];
self.navigationItem.leftBarButtonItem = myButton;
您還可以自定義標題。
例如
self.title = @"Your custom title";
- 在代碼中的某個位置創建
UINavigationController
,并將MyController
的實例添加為根視圖控制器。
例如:
MyController* myCtr = // alloc-init here
UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:myCtr];
這篇關于UIBarButton不會在我的UINavigationController中顯示的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持IT屋!
查看全文