0

关于ios开发的菜鸟问题。

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

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

这很好用。

我现在有另一个应用程序,我试图在其中做同样的事情,除了现在我在顶部有一个 UITabBarControllerDelegate(“选项卡栏应用程序”附带的默认值),它的第一个视图是 UITableViewController。

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

因此,在 firstViewController(这是一个 UITableViewController)中,我将上述代码添加到 viewDidLoad 方法中,但没有成功。

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

有任何想法吗?显然我不明白一些事情。

谢谢!

4

2 回答 2

2

如果我没记错的话,您需要将 UITableViewController 放在 UINavigationController 中才能显示 UIBarButtonItems。

于 2011-06-06T17:28:55.243 回答
0

做这个。

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

    //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

于 2011-06-06T17:44:16.757 回答