将 UITableView DataSource/Delegate 连接到基 UIViewController 类 [英] Connect UITableView DataSource/Delegate to base UIViewController class

查看:30
本文介绍了将 UITableView DataSource/Delegate 连接到基 UIViewController 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过情节提要将我的 UITableView 的数据源和委托连接到我的 ViewController 的基类.我能够轻松地连接我的 IBActions 和 IBOutlets,但事实证明这更棘手.

I'm attempting to connect my UITableView's DataSource and Delegate to my ViewController's base class via the storyboard. I Was able to connect my IBActions and IBOutlets easily, but this is proving trickier.

实例化委托/数据源方法然后在 super 上调用相同方法的正确方法是什么?

Is the correct method to instantiate the delegate/datasource methods then call the same methods on super?

TIA

推荐答案

Xcode 将对您尝试连接的对象进行类型检查.所以有两个先决条件:

Xcode will type-check the objects you attempt to connect. So there are two pre-requisites:

  1. 您的类的对象必须存在"在故事板中,这通常涉及在检查器中的 UIViewController 上设置自定义类
  2. 在您建立连接之前,您的对象的类必须声明它符合正确的协议.

如果满足这两个条件,您应该能够按住 ctrl 单击 UITableViewController,然后从这些连接拖动到您的类的对象,无论是在情节提要中还是在左侧的对象列表中.

If those two criteria are met, you should be able to ctrl-click on the UITableViewController, and drag from these connections to an object of your class, either in the storyboard or in the list of objects on the left.

我添加了一张通过按住 ctrl 单击表视图,然后从弹出窗口拖动到符合协议的视图控制器的两步方法设置委托的图片.此技术适用于左侧的列表视图以及工作区中的图形表示.

I have added a picture of setting the delegates via the two-step method of ctrl-clicking the table view, then dragging from the popover to the protocol-conforming view controller. This technique works with both the list view on the left as well as the graphical representations in the workspace.

这篇关于将 UITableView DataSource/Delegate 连接到基 UIViewController 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆