2011-01-27 11 views
0

私はUITableViewCellのcontentViewを2つのラベルにカスタマイズしました。UITableViewCellハイライト - コンテンツビューの複製

ただし、セルを選択/強調表示すると、contentView自体が重複しているようです。

はここで(前の)例を示します(ハイライト)した後 enter image description here

enter image description here

ここでは、セルのための私のコードです:

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 

    UILabel *mainLabel = [[[UILabel alloc] init] autorelease]; 
    UILabel *detailedLabel = [[[UILabel alloc] init] autorelease]; 
    [mainLabel setFont:[UIFont boldSystemFontOfSize:18.0f]]; 
    [detailedLabel setFont:[UIFont systemFontOfSize:13.0f]]; 

    mainLabel.frame = CGRectMake(51, 5, 0, 0); 
    mainLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

    detailedLabel.frame = CGRectMake(51, 23, 0, 0); 
    detailedLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

    NSString *text = [documents objectAtIndex:indexPath.row]; 
    mainLabel.text = [text stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@".%@", [text pathExtension]] withString:@""]; 
    NSString *extDescription = [self extensionDescriptionFromExtension:[text pathExtension]]; 
    NSString *fileSize = [self getFileSize:[NSString stringWithFormat:@"%@/Documents/%@", documentsDirectory, text]]; 
    detailedLabel.text = [NSString stringWithFormat:@"%@ - %@", fileSize, extDescription]; 
    cell.imageView.image = [UIImage imageNamed:@"txtIcon.png"]; 

    [cell.contentView addSubview:mainLabel]; 
    [cell.contentView addSubview:detailedLabel]; 

    return cell; 

} 

すべてのヘルプ高く評価しました。

+3

そのためにあらかじめ定義されたセルスタイルがあります。なぜこれを使わないの? – Axel

+0

私はUITableViewCellStyleSubtitleを忘れてしまった!ありがとう、私の仕事をより簡単に! –

答えて

1

UITableViewCellStyleSubtitleで動作しました。 enter image description here