Reputation: 2025
I want to use UIView
as a cell in UITableView
, any suggestions or examples on how to do that?
Upvotes: 1
Views: 2654
Reputation: 24967
You can add in UITableViewCell contentView. I used like following
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UILabel* lbl=[[UILabel alloc] initWithFrame:CGRectMake(10, 5, 80, 35)];
lbl.text=@"Email";
lbl.tag=1;
lbl.backgroundColor=[UIColor clearColor];
lbl.font=[UIFont fontWithName:@"Helvetica-Bold" size:20];
[cell.contentView addSubview:lbl];
}
UILabel* lbl=(UILabel*)[cell.contentView viewWithTag:1];
lbl.text=@"Your Text";
Upvotes: 1
Reputation: 6402
Make a custom cell by inheriting UITableviewCell and use that custom cell instead of default table view cell
Upvotes: 0
Reputation: 1279
The UITableViewCell has a readonly property contentView. It returns the content view of the cell object. You can manipulate this view for your needs, add subviews and do what you want. The 2nd approach is to subclass the UITableViewCell and design it in the interface builder.
Upvotes: 6