如何 link Table dataSource 和 delegate outlets 到 UITableViewController?

How to link Table dataSource and delegate outlets to UITableViewController?

我是 Swift/iOS 开发新手。

我的 storyboard 中有一个 UITableView,我想填充一些数据。在尝试这样做时,我创建了一个继承自 UITableViewController 的 class。实现尚未完成,但我的理解是,通过继承此 class 我可以为 dataSourcedelegate.

提供 IBOutlet

当我尝试将插座拖到源文件中时,我没有得到我之前测试时得到的插入点。见下图:

我需要做什么才能将此 class 定义为 UITableView 的处理程序?

如果您使用自己的 UITableView,继承自 UIViewController,而不是 UITableViewController

但是,如果您想在情节提要中使用 UITableViewController(我个人不使用),那么请继承自 UITableViewController。在这种情况下,您不必连接 UITableViewDataSourceUITableViewDelegate.

在您的故事板中,select UITableView 并将其更改为您的 UITableViewController 子类的名称。然后你不需要做任何链接的事情。

将您的 viewController 设置为从 UIViewController 继承,而不是从 UITableViewController 继承(看起来您的 IB 就是这样设置的)。 不要忘记在界面生成器上将 class 设置为 ZeroconfTableController

然后,您将可以设置 delegatedatasource。注意:delegatedatasource 不会创建 IBOutlet

按以下方式分配 delegatedataSource

还要确保您的 viewController 符合协议。

class ZeroconfTableController: UIViewController, UITableViewDataSource, UITableViewDelegate {