多个 UITableViews 中的多个 UITableViewCells [英] multiple UITableViewCells in multiple UITableViews

查看:18
本文介绍了多个 UITableViews 中的多个 UITableViewCells的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 UITableViews,每个都有(相当复杂的)自定义单元格.但是,其中一些自定义单元格是相同的.一个例子会让事情变得清楚

I have a few UITableViews each with (rather complex) custom cells. Some of those custom cells are the same however. An example will make things clear

tableView1 有 customCell1、customCell2tableView2 有 customCell3、customCell2tableView3 有 customCell1、customCell3...

tableView1 has customCell1, customCell2 tableView2 has customCell3, customCell2 tableView3 has customCell1, customCell3 ...

我可以为那些继承自 UITableViewCell 的 customCell 创建类.我可以控制将 customCell1 中的标签/图像视图从 tableview1 拖动到该类以创建插座.但是如何在 tableView3 中创建 customCell1 并连接插座?

I can create classes for those customCells inheriting from UITableViewCell. I can control-drag the labels/imageviews from customCell1 from tableview1 to that class to create the outlets. But how do I create a customCell1 in tableView3 and connect the outlets ?

推荐答案

我认为最好的选择是在单独的 xib 中提取单元格,在 viewDidLoad() 中加载 xib 并为每个单元注册它们UITableView.

I think that your best option is to extract your cells in separate xibs, load xibs inside viewDidLoad() and register them for each UITableView.

因此,在提取单元格后,将每个类的出口连接到特定单元格,然后使用以下内容:

So, after extracting cells, connect outlets for each class to the particular cells, and then use the following:

var nib1  = UINib(nibName: "customCell1", bundle:nil)
tableView1.registerNib(nib1, forCellReuseIdentifier: "customCell1")

依此类推,对于每个单元格和每个 tableView.

and so on, for each cell and each tableView.

之后,您可以简单地在 cellForRowAtIndexPath 方法中使这些单元格出列.在这里,您可以为每个 UI 元素设置值并在您需要的每个 tableView 上重复使用它们.

After that you can simply dequeue these cells in cellForRowAtIndexPath method. Here, you can set the values for each UI element and reuse them on every tableView you need.

这篇关于多个 UITableViews 中的多个 UITableViewCells的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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