2011-01-20 31 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