Can I create a UITableViewController that inherits from a custom subclass of UIViewController?

I have a common functionality with which I need to access from all screens of my application: the right button element and the action associated with it.

In order not to repeat the code, I would like to install it in a custom UIViewController and inherit all of my controllers from it.

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

However, I have several UITableViewControllers, and I would like to know if it is also possible to inherit functionality from them?

+6
objective-c iphone cocoa-touch uitableview uiviewcontroller
source share
2 answers

It is pretty trivial to recreate your own UITableViewController from your custom subclass of UIViewController .

The controller must have the UITableView property, also set in its view property, set the correct masks for resizing, set itself as a table delegate and data source, and do not make the scroll bar indicators blink in -viewDidAppear: and you more or less get it.

More details here .

+6
source share

If you do not add any new attributes to the view controller, you can implement two methods in the category in the UIViewController, and all subclasses inherit it by default.

+2
source share

All Articles