tableView的单元格的定制的方法

来源:互联网 发布:seo数据是什么 编辑:程序博客网 时间:2024/05/16 19:04
1、在 cellForRowAtIndexPath 函数中创建

//定制单元格
        
UILabel *nameLabel = [[UILabel allocinitWithFrame:CGRectMake(90520030)];
        nameLabel.
tag =12;
 
 然后通过tag的值来获取控件
UILabel *nameLabel =(UILabel *)[cell.contentView viewWithTag:12];

2、创建一个MyCell类继承UITableViewCell类,然后重写初始化函数

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
if (self) {
        
UIImageView *imageview = [[UIImageView allocinitWithFrame:CGRectMake(5306868)];
        imageview.
tag =11;
        [
self.contentView addSubview:imageview];
        
        
UILabel *nameLabel = [[UILabel allocinitWithFrame:CGRectMake(90520030)];
        nameLabel.
tag =12;
        [
self.contentView addSubview:nameLabel];
        
UILabel *nickLabel = [[UILabel allocinitWithFrame:CGRectMake(904020030)];
        nickLabel.
tag =13;
        [
self.contentView addSubview:nickLabel];
        
        
UILabel *dateLabel = [[UILabel allocinitWithFrame:CGRectMake(907520030)];
        dateLabel.
tag =14;
        [
self.contentView addSubview:dateLabel];
    }
    
return self;
}


3、通过xib创建,但是需要向tableview中注册,在控制器cellForRowAtIndexPath函数中注册

  static BOOL b=NO;
    
if (!b) {
        
UINib *nib = [UINib nibWithNibName:@"Cell" bundle:[NSBundle mainBundle]];
        [tableView 
registerNib:nib forCellReuseIdentifier:@"mycell"];
        b = 
YES;
    }
原创粉丝点击