您的位置:首页 > 产品设计 > UI/UE

IOS--自定义UITableViewCell

2015-10-26 13:51 369 查看
在用到UITableVIew的时候,经常会自定义每行的Cell

IOS控件UITableView详解中的下面代码修改部分代码就可以实现自定义的Cell了

[cpp] view
plaincopy

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

自定义代码:

[cpp] view
plaincopy

static NSString *CellWithIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];

if (cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellWithIdentifier];

}

NSUInteger row = [indexPath row];

// 自定义Cell中Image

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 24, 24, 24)];

imageView.image = [UIImage imageNamed:@"green.png"];

[cell.contentView addSubview:imageView];

[imageView release];

// 自定义文本信息

UILabel *city = [[UILabel alloc] initWithFrame:CGRectMake(50, 25, 100, 20)];

NSString *cityString = [[NSString alloc] initWithFormat:@"城市:%@",[self.dataList objectAtIndex:row]];

city.text = cityString;

[cell.contentView addSubview:city];

[cityString release];

// cell.textLabel.text = [self.dataList objectAtIndex:row];

// cell.imageView.image = [UIImage imageNamed:@"green.png"];

// cell.detailTextLabel.text = @"详细信息";

// cell.accessoryType = UITableViewCellSelectionStyleGray;



(转自:http://blog.csdn.net/qq5306546/article/details/8078797)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: