2011-06-06 56 views
0

noob關於ios開發的問題。UIBarButton不會顯示在Tab控制器的表格視圖

在以前的項目,我有一個UITableViewController,對此我在viewDidLoad方法添加一個按鈕,像這樣:

UIBarButtonItem *button = [[UIBarButtonItem alloc] 
          initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh 
          target:self 
          action:@selector(addMeasurement:)]; 
self.navigationItem.rightBarButtonItem = button; 
[button release]; 

這個偉大的工程。

我現在有另一個應用程序,我試圖做同樣的事情,除了現在我有一個UITabBarControllerDelegate在頂部(默認伴隨着「標籤欄應用程序」),其第一個視圖是UITableViewController。

第一視圖沒有筆尖,因爲它只是一張桌子。我試圖用相同的代碼做同樣的事情,試圖在viewDidLoad方法中添加一個按鈕,但它不起作用。

因此,在第一個ViewController(這是一個UITableViewController)我將上面的代碼添加到viewDidLoad方法,沒有成功。

但是它顯示了表中的數據(來自managedObjectContext)。我也嘗試將代碼放在firstViewController的「initWithStyle」方法中,但這也不起作用。

任何想法?顯然我不理解某些東西。

謝謝!

+0

爲什麼要在委託上添加一個按鈕?將按鈕添加到第一個視圖。 – Legolas 2011-06-06 16:23:39

+0

我認爲這是我正在做的。我將它添加到FirstViewController(這是一個UITableViewController)。或者那是不正確的? – thekevinscott 2011-06-06 16:24:30

回答

0

做到這一點。

  1. 創建標籤欄控制器並將其設置爲您的rootController。

    //You will not have three tabs and you need three view controllers// 
    
  2. 將您的第一個視圖控制器設置爲導航視圖控制器。

    // You will now have the Navigation bar at the top// 
    
  3. 創建一個新的文件,它是UITableViewController的子類。

    // set this as your delegate and datasource for your table view controller methods// 
    // pull a table view controller inside the Navigation View Controller as mentioned in (2) & you will have a tableview and navigation view in FirstViewController. Similarly work with the other two tabs 
    

如果您有任何更多的疑慮;請看這個教程如何去做所有這些。

http://www.youtube.com/watch?v=LBnPfAtswgw

+0

太棒了!謝謝你的提示 – thekevinscott 2011-06-06 20:14:57

2

如果我沒有弄錯你需要在UINavigationController中有你的UITableViewController來顯示UIBarButtonItems。

相關問題