tableview的显示的样式主要是在于这几种:
我要重点介绍的是第四种---在一个cell里面分行显示数据(相当于主标题和副标题)
typedef enum {
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
主要是在于这两段代码:
- (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- NSDictionary *item = (NSDictionary *)[self.content objectAtIndex:indexPath.row];
- cell.textLabel.text = [item objectForKey:@"mainTitleKey"]; 主标题-top
- cell.detailTextLabel.text = [item objectForKey:@"secondaryTitleKey"]; 副标题-bottom
- NSString *path = [[NSBundle mainBundle] pathForResource:[item objectForKey:@"imageKey"] ofType:@"png"];
- UIImage *theImage = [UIImage imageWithContentsOfFile:path];
- cell.imageView.image = theImage;
- return cell;