2011-01-20 15 views

答えて

3

2つのオプションがあります(さらに多くの可能性があります)。ネイティブのUITableViewCellプロパティを使用してセルにコンテンツを追加したり、カスタムセルを作成したりすることができます(つまり、独自のサブビューをCellに追加することによって)。最初のものを試してみると、それはシンプルでエレガントで、結果はかなり良いでしょう。たとえば、次のセルの作成方法試してください:

- (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つのプロパティを持っていることができます:

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

その後、あなたは(のdrawRect :)機能を用いて細胞にそれらを描くことができます:

- (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]]; 
    } 

さらに詳しい例については、このスタイルを使用するこのフレームワークをチェックしてみてください:https://github.com/andrewzimmer906/XCell

関連する問題