UIBarButton将不会显示在选项卡控制器中的表视图上 [英] UIBarButton won't show up on Table View within Tab Controller

查看:83
本文介绍了UIBarButton将不会显示在选项卡控制器中的表视图上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关ios开发的新手问题.

在先前的项目中,我有一个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>

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

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

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

有什么想法吗?显然我不了解某事.

谢谢!

解决方案

执行此操作.

  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

noob question regarding ios development.

In a previous project, I have a UITableViewController, to which I am adding a button in the viewDidLoad method, like this:

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

This works great.

I now have another application in which I am trying to do the same thing, except now I have a UITabBarControllerDelegate at the top (the default that comes along with "Tab Bar Application"), whose first view is the UITableViewController.

The First View has no nib as it's just a table. I am trying to do the same thing with the same code, trying to add a button in the viewDidLoad method, but it's not working.

So in the firstViewController (which is a UITableViewController) I am adding the above code to the viewDidLoad method, with no success.

It is showing data in the table, however (from a managedObjectContext). I've also tried putting the code in the "initWithStyle" method of the firstViewController but that doesn't work either.

Any ideas? Clearly I'm not understanding something.

Thanks!

解决方案

Do this.

  1. Create the Tab Bar Controller and set it as your rootController.

    //You will not have three tabs and you need three view controllers//
    

  2. Set your First View controller as a Navigation View controller.

    // You will now have the Navigation bar at the top//
    

  3. Create a new file which is a subclass of the 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
    

If you have any more doubts; please watch this tutorial on how to do all of these.

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

这篇关于UIBarButton将不会显示在选项卡控制器中的表视图上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆