4

How do I customize each cell in a UITableView (like each cell will have UITextfield and UIButton)?

Cœur
  • 34,719
  • 24
  • 185
  • 251
ebaccount
  • 5,031
  • 11
  • 42
  • 47

2 Answers2

3

UITableView cells respond to selections - it get's handled in tableView:didSelectRowAtIndexPath, maybe this satisfies your UIButton requirement. In case where you need UIButton it should not be difficult - it is just another UIView component.

Easy custom UITableView drawing is a detailed article on customizing UITableView. It goes beyond what you want but you may find useful details. Have a look at section Layout within the contentView for how to add views to cell - the example adds image and text (lots of custom background stuff going on).

Example code discussed 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;

Maybe have a look at question UIButton in a UITableView header ignores most touches.

Community
  • 1
  • 1
stefanB
  • 73,317
  • 26
  • 115
  • 141
1

There era a few subViews in table cell that you can modify. Good tutorial that I found is here: http://www.cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

Cœur
  • 34,719
  • 24
  • 185
  • 251
Vitalii Boiarskyi
  • 1,343
  • 2
  • 10
  • 25