ios - 如何在原型(prototype)单元格上使用 UITableView 单元格及其元素

标签 ios ipad uitableview interface-builder

我已经使用这个Master-Detail 应用程序开始了一个新的 iPad 项目。我不太喜欢使用 Interface Builder 创建东西,但对于这个项目,我必须特别使用它。

我需要创建一个自定义单元格以在 MasterViewController 上使用。此单元格将包含一个开关和一个标签。使用界面生成器,我已将这些元素拖到所谓的 TableView Prototype Content 中的 Prototype Cells。

这是我得到的。

enter image description here

现在如何在 tableView:cellForRowIndexPath: 中使用它?我必须要有 socket 才能使用 UILabelUISwitch 吗?我该怎么做?

谢谢

最佳答案

是的。您应该创建一个 UITableViewCell 子类,并为您需要访问的每个控件添加 IBOutlets。然后,您将子类设置为身份检查器中每个原型(prototype)单元格的自定义类。

您还需要设置重用标识符。然后,您可以像通常在 tableView:cellForRowIndexPath::

中那样对单元格进行出队
YourCustomCellClass *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

关于ios - 如何在原型(prototype)单元格上使用 UITableView 单元格及其元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23889970/

相关文章:

IOS——文件和文件夹管理

ios - 如何使用 MVVM 处理 UITableViewCell 中的 UICollectionView

ios - 滚动表格 View 时值会发生变化

ios - -[UIViewController tableView :numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fc748e37ea0'

ios - TableView 在重新加载时显示重复的单元格

ios - setStatusBarHidden 已弃用,但唯一有效的方法

iphone - @2x 如何用于视频?

iOS iTunes 专辑封面类型(或类似)图像显示

ios - 当键盘出现在 SwiftUI 中时向上移动 TextField

ios - 在 UISearchDisplayController 后面重新加载 UITableView