【问题标题】:Objective c inheritance/protocol confusion: UITableViewControllerObjective c 继承/协议混淆:UITableViewController
【发布时间】:2011-07-31 20:09:11
【问题描述】:

现在,我正试图围绕 Objective C 和 XCode 展开思考。我在玩UITableView,但我在分离背后的概念时遇到了问题

  • UITableViewController
  • UITableViewDelegate
  • UITableViewDataSource

我熟悉 MVC 模式,我从 Apple Developer Docs 中了解到,他们的框架使用委托来“专门化”类而无需子类化,并且数据源类定义了如何将数据从模型映射到视图(请如果我错了,请纠正我)。

当我通过选择 New File.. > Cocoa Touch Class > UIViewController 子类(检查 UITableViewController 子类)创建 TableViewController 时,我很困惑地看到模板包含 UITableViewDelegate 和 UITableViewDataSource 中的所有函数,但没有在头文件中指定 TableViewController 实现这些协议。 UITableViewController 的文档说它“符合 UITableViewDelegate 和 UITableViewDataSource”。这是否意味着它实现了这些协议?

所以我的问题是:UITableViewController 仅仅是结合 UITableViewDelegate 和 UITableViewDataSource 的便利类,还是我遗漏了什么?如果我提供单独的 UITableViewDelegate 和 UITableViewDataSource,我是否需要 UITableViewController?

谢谢!

【问题讨论】:

    标签: iphone objective-c cocoa-touch xcode cocoa-design-patterns


    【解决方案1】:

    UITableViewController 是一个预先配置有 UITableView 的控制器,并且它本身被设置为 table view 的委托和数据源。

    所以是的,它几乎是一个便利类。

    您不需要使用它,特别是如果您提供自己的数据源和委托。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      相关资源
      最近更新 更多