表格单元格视图中的多个标签 [英] Multiple labels in a table cell view

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

问题描述

我想动态地将三个标签添加到单元格中,单元格也是动态创建的,但是我不知道如何创建标签并将其添加到Objective-C(iPhone)中的单元格中.有人可以帮我吗?

I want to add three labels into a cell dynamically, cell is created dynamically as well, but I don't know how to create labels and add it into the cell in Objective-C (iPhone). Can anybody help me?

推荐答案

通过动态",我假设您的意思是通过代码而不是通过Interface Builder.我还假设您知道如何使用 -tableView:cellForRowAtIndexPath:.

By "dynamically" I assume you mean via code, not via Interface Builder. I also assume you know how to use -tableView:cellForRowAtIndexPath:.

然后事情很简单.UITableViewCell具有只读的 contentView 属性.您只需将三个UILabel添加为 contentView 的子视图即可.

Then things are simple. The UITableViewCell has a readonly contentView property. You can just add your three UILabel's as a subview of contentView.

UIView* view = cell.contentView;
UILabel* label1 = [[UILabel alloc] initWithFrame:…];
…
[view addSubview:label1];
[label1 release];
…

这篇关于表格单元格视图中的多个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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