自定义TableViewCell内容
1. 可以通过在实例化TableCell的时候,动态添加各个控件, -(UITableViewCell *)tableView:(UITableView
*)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath{ UILabel *label=[UILabelalloc] init]; Label.xx=xxxx; . . .
label.xx=xxxx;
[Cell addSubViews:label] };
在通过遍历,获取动态添加的控件,然后设置控件要实际显示/操作内容。 2. 可以先创建一个父类为UITableViewCell的xib文件,然后在此xib文件中设置各个需要添加的属性内容。
然后在实际要显示的TableView里面添加此TableViewCell的xib文件, 添加步骤为:
staticNSString *myCellIdentifier = @"Cell"; // 在xib文件里有这个Identifier的 if (!nibRegistered)
{
//向当前TableView注册TableCell的信息,然后才能进行添加操作 UINib *nib = [UINibnibWithNibName:@"FacilityTableCell"bundle:nil];
[tableViewregisterNib:nibforCellReuseIdentifier:myCellIdentifier]; nibRegistered = YES; }
// 单元格内容
FacilityTableCell *cell = [tableViewdequeueReusableCellWithIdentifier:myCellIdentifier]; if (cell == nil) {
cell = [[[FacilityTableCellalloc]
initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:myCellIdentifier] autorelease]; }
cell.delegate = self;
// cell选中时的颜色:无色
cell.selectionStyle = UITableViewCellSelectionStyleNone;