2011-01-20 50 views

回答

3

有两种选择(可能会更多)。您可以使用本机UITableViewCell属性将内容添加到单元格,或创建一个自定义单元格(我的意思是,将您自己的子视图添加到单元格中)。要开始尝试第一个,它简单优雅,结果会相当不错。例如试试下面的单元格创建方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     // notice the Style. The UITableViewCell has a few very good styles that make your cells look very good with little effort 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell... 
    // In my case I get the data from the elements array that has a bunch on dictionaries 
    NSDictionary *d = [elements objectAtIndex:indexPath.row]; 

    // the textLabel is the main label 
    cell.textLabel.text = [d objectForKey:@"title"]; 

    // the detailTextLabel is the subtitle 
    cell.detailTextLabel.text = [d objectForKey:@"date"]; 

    // Set the image on the cell. In this case I load an image from the bundle 
    cell.imageView.image = [UIImage imageNamed:@"fsaint.png"]; 

    return cell; 
} 
0

我重写的UITableViewCell类,并做风俗画self.contentView的忠实粉丝。这种技术稍微复杂一些,但它会带来更好的滚动性能。

例如,假设你重写你的细胞,并有3个属性就可以了,像这样:

- (void)drawRect:(CGRect)rect { 
    [super drawRect:rect]; 
    [userPic drawInRect: CGRectMake(10, 5, 50, 50)]; 
    [label drawAtPoint:CGPointMake(70, 5) withFont:[UIFont boldSystemFontOfSize:17]]; 
    [date drawAtPoint:CGPointMake(70, 30) withFont:[UIFont systemFontOfSize:14]]; 
    } 

@property(nonatomic, retain) UIImage *userPic; 
@property(nonatomic, retain) NSString *label; 
@property(nonatomic, retain) NSString *date; 

然后你可以使用(drawRect中:)功能吸引他们在细胞

欲了解更多示例,请查看此框架使用此款式:https://github.com/andrewzimmer906/XCell