zoukankan      html  css  js  c++  java
  • IOS自定义UITableViewCell

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

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

    [cpp] view plaincopy
     
    1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  

    自定义代码:

    [cpp] view plaincopy
     
    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;  


  • 相关阅读:
    Pandas学习整理与实践
    数据描述性统计整理
    关于购置硬盘的相关注意点
    福大软工 · 最终作业
    福大软工 · 第十二次作业
    Beta冲刺 (7/7)
    Beta冲刺 (6/7)
    深度剖析Vue中父给子、子给父、兄弟之间传值!
    mysql 增删改插
    前端必学TypeScript之第一弹,st基础类型!
  • 原文地址:https://www.cnblogs.com/aggie/p/4518603.html
Copyright © 2011-2022 走看看