Графика в ячейках UITableView исчезает - PullRequest
0 голосов
/ 13 июля 2011

У меня возникла странная проблема, когда я помещаю некоторый текст в ячейку (используя cell.textLabel) и небольшую «галочку» справа от ячейки. Когда я выбираю ячейку, галочка должна появляться или исчезать, если она уже есть. Что действительно происходит, так это то, что галочка появляется, а затем почти мгновенно исчезает. Это все довольно стандартный код, так что если кто-нибудь знает, что происходит, я буду рад услышать!

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

NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];


static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
} else {
    while ([[cell.contentView subviews] count] > 0) {
        UIView *labelToClear = [[cell.contentView subviews] objectAtIndex:0];
        [labelToClear removeFromSuperview];
    }
}


NSString *theName = [[contacts objectForKey:[contactsKeys objectAtIndex:section]] objectAtIndex:row];

cell.textLabel = theName;


if (section == 0) {
    cell.textLabel.textAlignment = UITextAlignmentCenter;
} else {
    cell.textLabel.textAlignment = UITextAlignmentLeft;
}


if ([selectedContacts containsObject:theName]) {

    CGFloat cellRight = tableView.frame.size.width - 70;

    UIImage *theTickImage = [UIImage imageNamed:@"Tick.png"];
    UIImageView *theTickImageView = [[[UIImageView alloc] initWithImage:theTickImage] autorelease];
    theTickImageView.frame = CGRectMake(cellRight, 10, theTickImage.size.width, theTickImage.size.height);

    [cell.contentView addSubview:theTickImageView];

}


return cell;

}

Большое спасибо за любую помощь!

1 Ответ

0 голосов
/ 13 июля 2011

Ну, я понял это - cell.textLabel сидел поверх моей графики, поэтому скрывал это.Я просто установил для свойства backgroundColor textLabel значение [UIColor clearColor], и все было хорошо - может быть, я мог бы поставить свою графику поверх textLabel, я еще не пробовал.

...