I have common functionality that I need to access from all screens of my app: a right bar button item and associated action.
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 {
…
}
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?
It's fairly trivial to recreate you own UITableViewController
from your custom UIViewController
subclass.
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.
More here .
如果您没有向视图控制器添加任何新属性,则可以在UIViewController上的类别中实现这两个方法,并且默认情况下所有子类都将继承它。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.