iphone - 从 UIViewController 子类化时如何访问 UITableViewController 属性?

标签 iphone objective-c uiviewcontroller uitableview

我已经对 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 一样工作(本质上这就是它所做的一切!)

看看at my article here which takes this approach.

关于iphone - 从 UIViewController 子类化时如何访问 UITableViewController 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7846808/

相关文章:

objective-c - 如何垂直居中对齐 NSTextField 中的文本?

ios - 如何在 UIViewController 中对 UICollectionView 进行单元测试

iphone - iphone 上的 iscroll : visual distortions. 我怀疑它与硬件有关?

iphone - colorWithPatternImage 和 setCornerRadius 问题

iPhone:将 NSLog 重定向到文件后,如何将其恢复到控制台?

ios - 如何使用按钮更改高度限制?

ios - 对不同的 ViewController 具有相同操作的自定义 UIButton 类

ios - init 方法与 viewDidLoad 类型的方法

iphone - 在 RootController 上调整 UITableView 的大小

iphone - xcode 中 uitextfield 的高度是多少(iphone)