4

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
ebaccount
  • 5,051
  • 11
  • 43
  • 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
  • 77,323
  • 27
  • 116
  • 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
  • 37,241
  • 25
  • 195
  • 267
Vitalii Boiarskyi
  • 1,363
  • 2
  • 10
  • 25