iPhone / Three20:将动态标签列表作为子视图添加到表格单元格
我正在使用 Three20
框架编写一个 iPhone 应用程序,并且正在努力弄清楚如何将 UILabel
的动态列表添加到表格单元格中。
我尝试对 TTTableTextItem
和 TTTableTextItemCell
进行子类化以显示我的动态列表,但我很难尝试编写 layoutSubviews
code>、setObject
和 initWithStyle
方法。
我在此处和此处 虽然我可以复制这些简单的示例,其中表格单元格具有静态数量的控件,但我仍然没有太多运气尝试重新创建某处某处控件的数量是根据传递到表格单元格的数据动态变化的。
我提取的数据是一个Employee
列表,每个员工都有一个包含一个或多个Job
的NSArray
(所以显然单元高度需要是动态的,代表作业的标签列表也是如此)。
每个作业都有一个名称和与其关联的颜色。
我的目的是创建类似于以下内容的单元格:
单元格一
- “员工一”
- “Job-1 颜色标签”“Job-1 名称标签”
- “Job-2 颜色标签”“Job-2 名称标签”
- ... .
- “作业 n 颜色标签” “作业 n 名称”
单元格二
- “员工二”
- “作业 1 颜色标签” “作业 1 名称标签”
- “作业 2 颜色标签” “作业 2 名称标签”
- .. ..
- “Job-n 颜色标签” “工作名称”
如果有人能帮助我指明正确的方向,我将不胜感激!
I'm writing an iPhone app using the Three20
framework and I'm struggling to figure out how I can add a dynamic list of UILabel
s to a table cell.
I've attempted to subclass a TTTableTextItem
and TTTableTextItemCell
in order to display my dynamic list, but I'm having a hard time trying to write the layoutSubviews
, setObject
and initWithStyle
methods.
I've read about subclassing here and here and whilst I can replicate these simple examples where the table cells have a static number of controls, I've still not had much luck attempting to recreate something where the number of controls are dynamic based on the data that is passed to the table cell.
The data I'm pulling is a list of Employee
s, and each employee has an NSArray
of one or more Job
s (so obviously the cell height needs to be dynamic, as does the list of labels that represent the jobs).
Each Job
has a name, and a colour associated with it.
My intention is to create cells that look similar to the following:
Cell One
- "Employee One"
- "Job-1 colour label" "Job-1 Name Label"
- "Job-2 colour label" "Job-2 Name Label"
- ....
- "Job-n colour label" "Job-n Name"
Cell Two
- "Employee Two"
- "Job-1 colour label" "Job-1 Name Label"
- "Job-2 colour label" "Job-2 Name Label"
- ....
- "Job-n colour label" "Job-n Name"
If someone could help point me in the right direction, that'd be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,没有一种简单的方法可以实现我在这里所追求的目标。 @tonklon 改变我的设计的建议是最好的选择,这正是我所做的。
From what I can tell, there isn't an easy way to do what I'm after here. @tonklon's suggestion of changing my design was the best option here and is exactly what I did.