我可以创建一个UITableViewController继承自UIViewController的自定义子类吗? [英] Can I create a UITableViewController that inherits from a custom subclass of UIViewController?

查看:202
本文介绍了我可以创建一个UITableViewController继承自UIViewController的自定义子类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些常用的功能,我需要从我的应用程序的所有屏幕访问:一个右栏按钮项和相关联的操作。

I have common functionality that I need to access from all screens of my app: a right bar button item and associated action.

为了不重复代码我想在一个自定义的UIViewController中设置,并让所有的视图控制器继承自它。

So as not to repeat the code I would like to set this up in a custom UIViewController and have all my view controllers inherit from it.

- (void)viewDidLoad {
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(lightsCamera)];
    self.navigationItem.rightBarButtonItem = rightBarButton;
}

- (void)lightsCamera {
    …
}

$ b b

然而,我有一些UITableViewControllers然而,我想知道他们是否可能继承的功能呢?

However, I have a number of UITableViewControllers however and I would like to know if it is possible for them to inherit the functionality too?

推荐答案

从您的自定义 UIViewController 子类重建您自己的 UITableViewController

It's fairly trivial to recreate you own UITableViewController from your custom UIViewController subclass.

控制器必须有一个 UITableView 属性,也设置为 / code>属性,设置适当的调整大小掩码,将自己设置为表的委托和数据源,并记住在 -viewDidAppear:中闪烁滚动条指示符,

The controller must have a UITableView property, which is also set to its view property, set the proper resizing masks, set yourself as the table's delegate and datasource, and remember to flash the scrollbar indicators in -viewDidAppear: and you've more or less got it.

更多此处

这篇关于我可以创建一个UITableViewController继承自UIViewController的自定义子类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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