【问题标题】:UITableView using instance methodsUITableView 使用实例方法
【发布时间】:2011-08-28 20:18:16
【问题描述】:

我一直在尝试在我的 UITableView 类中访问 UITableView 的一些实例方法,以按照本教程 http://www.raywenderlich.com/999/core-data-tutorial-how-to-use-nsfetchedresultscontroller 使用 NSFetchedResultsController

在本教程中有一段代码您正在访问 self.tableView,这是有道理的,因为您使用的是 UITableViewController。但是,我正在尝试使用 UITableView,但找不到任何使用它的示例。

查看文档,我应该有一个实例方法“beginUpdates”(reloadUpdates、insertRowsAtIndexPaths:withRowAnimation:) http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html

但是,当我尝试使用 [self beginUpdates] 访问实例方法时,我无法获取实例方法(未找到方法)。对于一堆实例方法来说就是这样,但不是全部。比如我可以访问

[self setEditing:(BOOL) animated:(BOOL)]

我对 Objective-C 比较陌生,所以我相信我以错误的方式访问我的 UITableView 实例,但我能想到的唯一的事情就是“自我”

如何在 UITableView 而不是 UITableViewController 中访问这些方法?

【问题讨论】:

  • 所以你要继承UITableView?
  • 谢谢你,我公然错过了。我将继承从 UIViewController 更改为 UITableView 并且它起作用了。
  • 不要那样做(tm)。这些方法属于视图控制器,而不是 UITableView。如果您使用的不是 UITableViewController 而是常规 UIViewController,则将表视图作为属性添加到该视图控制器。如果您将其命名为self.tableView,那么您应该能够完全按照您提到的教程中的方式使用它。
  • 我后来意识到这一点并设置了适当的 IBOutlets。

标签: ios cocoa-touch uitableview uiviewcontroller


【解决方案1】:

+1 @Hollance 的评论。您可能会发现您希望自定义视图控制器逻辑比子类化 UITableViewController 允许的更多,但这最好由 UIViewController 的子类提供,该子类由 UITableView 组成(即,tableView outlet/属性)。

【讨论】:

    猜你喜欢
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多