2013-03-22 121 views
0

我試圖在導航欄上添加編輯按鈕,但沒有成功。這似乎是一個簡單的任務,就像在蘋果文檔navigation controllers上說的那樣。編輯按鈕項目不會顯示在導航欄上

myViewController.navigationItem.rightBarButtonItem = [myViewController editButtonItem];

我的代碼:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

// [self retrievePassengerInformation]; 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 

enter image description here

以任何理由的編輯按鈕沒有顯示出來。只是爲了讓大家知道這是一個靜態分組的tableview。

任何幫助將不勝感激。 謝謝, Marcos

+0

什麼時候'editButtonItem'是怎麼被初始化,什麼是它的類型? – 2013-03-22 00:41:22

+0

@MikeD這是由UIViewController對象返回的屬性。 - (UIBarButtonItem *)editButtonItem – vilelam 2013-03-22 00:53:29

+1

@vilelam您的視圖控制器是在「UINavigationController」的內部,還是僅在視圖頂部添加了「UINavigationBar」? – rmaddy 2013-03-22 01:43:56

回答

0

ViewController沒有從導航控制器調用,因此不應該訪問self.navigationItem。我最終創建了一個插件來添加我的UINavigationItem並且它正在工作。

@property (weak, nonatomic) IBOutlet UINavigationItem *addedNavigationItem; 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

// [self retrievePassengerInformation]; 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 


    self.addedNavigationItem.rightBarButtonItem = self.editButtonItem; 
} 
0
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editMethodName:)]; 
self.navigationItem.rightBarButtonItem = editButton; 
+0

請看看我的答案。謝謝,馬科斯 – vilelam 2013-03-22 20:24:46