在用到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];
-
- 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];
-

IOS自定义UITableViewCell
原文:http://www.cnblogs.com/aggie/p/4518603.html