UIBarButton不会显示在选项卡控制器中的表视图上

时间:2011-06-06 16:21:15

标签: ios uitableview uibarbuttonitem uitabcontroller

关于ios开发的noob问题。

在之前的项目中,我有一个UITableViewController,我在viewDidLoad方法中添加了一个按钮,如下所示:

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

这很有效。

我现在有另一个应用程序我正在尝试做同样的事情,除了现在我在顶部有一个UITabBarControllerDelegate(默认情况下是“Tab Bar Application”),它的第一个视图是UITableViewController。 / p>

First View没有笔尖,因为它只是一张桌子。我试图用相同的代码做同样的事情,尝试在viewDidLoad方法中添加一个按钮,但它不起作用。

所以在firstViewController(这是一个UITableViewController)中我将上面的代码添加到viewDidLoad方法中,没有成功。

然而,它显示了表中的数据(来自managedObjectContext)。我也尝试将代码放在firstViewController的“initWithStyle”方法中,但这也不起作用。

有什么想法吗?显然,我不理解某些事情。

谢谢!

2 个答案:

答案 0 :(得分:2)

如果我没弄错的话,你需要在UINavigationController中使用你的UITableViewController才能显示UIBarButtonItems。

答案 1 :(得分:0)

这样做。

  1. 创建标签栏控制器并将其设置为rootController。

    //You will not have three tabs and you need three view controllers//
    
  2. 将First View控制器设置为导航视图控制器。

    // 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
    
  4. 如果你有任何疑问;请观看本教程,了解如何完成所有这些工作。

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

相关问题