在用到UITableVIew的时候,经常会自定义每行的Cell
在IOS控件UITableView详解中的下面代码修改部分代码就可以实现自定义的Cell了
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
自定义代码:
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;
