自定义TableViewCell内容

来源:互联网 发布:网络著作权侵权认定 编辑:程序博客网 时间:2024/06/06 12:59

自定义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; 


//    // cell选中时的颜色:蓝色 
//    cell.selectionStyle = UITableViewCellSelectionStyleBlue; //    // cell选中时的颜色:灰色 
//    cell.selectionStyle = UITableViewCellSelectionStyleGray;  
// 数据项 
FacilityModel *item = [facilityArrayobjectAtIndex:indexPath.row]; cell.facilityID = item.facilityID; 
. . . . 
cell.lblEmail.text = item.email; return cell; 
0 0
原创粉丝点击