我已经对 UIViewController 进行了子类化,以为所有 UIViewController 提供通用功能(例如,我正在重写 viewDidLoad 方法)。我的应用程序使用一堆 View Controller ,这些 View Controller 排列在选项卡栏 Controller 和导航 Controller 内。一切都很好,除了我有一个 UITableViewController。我想继承的不是它,而是我的自定义 MyUIViewController。我可以通过实现数据源和委托(delegate)协议(protocol)来使表正常工作:
@interface MaschinenTableViewController : MyUIViewController <UITableViewDataSource, UITableViewDelegate>
但是在这种情况下,我无权访问 UITableViewController 属性。例如,我无法更改表行选择的行为,因为 self 是 MyUIViewController 而不是 UITableViewController:
self.clearsSelectionOnViewWillAppear = YES;
是否有访问这些属性的解决方法?
最佳答案
在这种情况下,您需要将 UITableView 变量添加到标题中,并在 viewDidLoad 中对其进行适当设置,然后将其添加到您的 View 中。从此时起,它将像 UITableViewController 一样工作(本质上这就是它所做的一切!)
关于iphone - 从 UIViewController 子类化时如何访问 UITableViewController 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7846808/