您的位置:首页 > 其它

tableView的单元格的定制的方法

2013-11-08 10:05 141 查看
1、在 cellForRowAtIndexPath 函数中创建

//定制单元格

UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 200, 30)];

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 alloc] initWithFrame:CGRectMake(5, 30, 68, 68)];

imageview.tag =11;

[self.contentView addSubview:imageview];

UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 200, 30)];

nameLabel.tag =12;

[self.contentView addSubview:nameLabel];

UILabel *nickLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 40, 200, 30)];

nickLabel.tag =13;

[self.contentView addSubview:nickLabel];

UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 75, 200, 30)];

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: