我可以创建一个继承自UIViewController的自定义子类的UITableViewController吗?

pre*_*io2 6 iphone cocoa-touch objective-c uitableview uiviewcontroller

我有我需要从我的应用程序的所有屏幕访问的常用功能:右键栏项和相关操作.

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

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

- (void)lightsCamera {
    …
}
Run Code Online (Sandbox Code Playgroud)

但是,我有许多UITableViewControllers,我想知道他们是否有可能继承这些功能?

jbr*_*nan 6

UITableViewController从自定义UIViewController子类重新创建自己是非常简单的.

控制器必须有一个UITableView属性,该属性也设置为其view属性,设置适当的大小调整掩码,将自己设置为表的委托和数据源,并记住闪存滚动条指示器-viewDidAppear:,你或多或少得到它.

更多这里.