tableview 显示主副标题的样式

来源:互联网 发布:恒腾网络 股吧 编辑:程序博客网 时间:2024/04/30 05:29


tableview的显示的样式主要是在于这几种:

我要重点介绍的是第四种---在一个cell里面分行显示数据(相当于主标题和副标题)


typedefenum {

    UITableViewCellStyleDefault,// Simple cell with text label and optional image view (behavior of UITableViewCell in iPhoneOS 2.x 显示标签和图片的简单表单元

    UITableViewCellStyleValue1,// Left aligned label on left and right aligned label on right with blue text (Used in Settings)

    UITableViewCellStyleValue2,// Right aligned label on left with blue text and left aligned label on right (Used in Phone/Contacts)

    UITableViewCellStyleSubtitle// Left aligned label on top and left aligned label on bottom with gray text (Used in iPod).

} UITableViewCellStyle;            // available in iPhone OS 3.0



主要是在于这两段代码:


  1. (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
  2.   
  3.    
  4.   
  5.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];  
  6.   
  7.     if (cell == nil) {  
  8.   
  9.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];  
  10.   
  11.         cell.selectionStyle = UITableViewCellSelectionStyleNone;  
  12.   
  13.     }  
  14.   
  15.     NSDictionary *item = (NSDictionary *)[self.content objectAtIndex:indexPath.row];  
  16.   
  17.     cell.textLabel.text = [item objectForKey:@"mainTitleKey"];  主标题-top
  18.   
  19.     cell.detailTextLabel.text = [item objectForKey:@"secondaryTitleKey"]; 副标题-bottom 
  20.   
  21.     NSString *path = [[NSBundle mainBundle] pathForResource:[item objectForKey:@"imageKey"] ofType:@"png"];  
  22.   
  23.     UIImage *theImage = [UIImage imageWithContentsOfFile:path];  
  24.   
  25.     cell.imageView.image = theImage;  
  26.   
  27.     return cell;  

原创粉丝点击