首页 > 其他 > 详细

ios之UITabelViewCell的自定义(代码实现)

时间:2014-02-15 16:30:55      阅读:269      评论:0      收藏:0      [点我收藏+]

在用到UITableVIew的时候,经常会自定义每行的Cell

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

 

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

 

自定义代码:

 

  1. static NSString *CellWithIdentifier = @"Cell";  
  2.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];  
  3.     if (cell == nil) {  
  4.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellWithIdentifier];  
  5.     }  
  6.       
  7.       
  8.     NSUInteger row = [indexPath row];  
  9.     // 自定义Cell中Image  
  10.     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 24, 24, 24)];  
  11.     imageView.image = [UIImage imageNamed:@"green.png"];  
  12.     [cell.contentView addSubview:imageView];  
  13.     [imageView release];  
  14.      
  15.     // 自定义文本信息  
  16.     UILabel *city = [[UILabel alloc] initWithFrame:CGRectMake(50, 25, 100, 20)];  
  17.     NSString *cityString = [[NSString alloc] initWithFormat:@"城市:%@",[self.dataList objectAtIndex:row]];  
  18.     city.text = cityString;  
  19.     [cell.contentView addSubview:city];  
  20.     [cityString release];  
  21.       
  22. //    cell.textLabel.text = [self.dataList objectAtIndex:row];  
  23. //    cell.imageView.image = [UIImage imageNamed:@"green.png"];  
  24. //    cell.detailTextLabel.text = @"详细信息";  
  25. //    cell.accessoryType = UITableViewCellSelectionStyleGray;  


bubuko.com,布布扣

ios之UITabelViewCell的自定义(代码实现)

原文:http://www.cnblogs.com/yulang314/p/3550486.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!