2011-01-27 2 views
0

Я настроил содержимое ContentView UITableViewCell на 2 ярлыка.UITableViewCell Highlighted - дублирование содержимого Просмотр

Однако, когда я выбираю/выделяю ячейку, 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

Смежные вопросы