如何自定义UITableView
中的每个单元格(每个单元格都有UITextfield
和UIButton
)?
答案 0 :(得分:3)
UITableView
单元格会对选择做出响应 - 它会在tableView:didSelectRowAtIndexPath
中处理,也许这会满足您的UIButton要求。如果您需要UIButton,它应该不难 - 它只是另一个UIView组件。
Easy custom UITableView drawing是一篇关于自定义UITableView
的详细文章。它超出了你想要的范围,但你可能会发现有用的细节。看看contentView 中的布局部分,了解如何向单元格添加视图 - 该示例添加了图像和文本(大量自定义背景内容)。
讨论的示例代码here:
UIView* container = [[UIView alloc] initWithFrame:goodRect];
UITableView* tv = [[UITableView alloc] initWithFrame:tableRect];
UIButton* btn = [[UIButton alloc] initWithFrame:btnFrame];
[container addSubview:tv];
[container addSubview:btn];
myController.view = container;
或许可以查看问题UIButton in a UITableView header ignores most touches。
答案 1 :(得分:1)
表格单元格中有一些可以修改的子视图。我找到的好教程在这里:http://www.cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html