UIBarButton不会显示在Tab控制器的表格视图

问题描述:

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

做到这一点。

  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

如果我没有弄错你需要在UINavigationController中有你的UITableViewController来显示UIBarButtonItems。