2011-07-13 162 views
0

發生了一個奇怪的問題,我在單元格中放置了一些文本(使用cell.textLabel)和一個小「勾號」圖形。當我選擇單元格時,應該顯示標記,如果已經存在,則消失。實際上發生的是滴答滴答然後幾乎立即淡出。這都是非常標準的代碼,所以如果任何人有任何想法發生了什麼,我會很高興聽到!UITableView單元格中的圖形消失

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

} 

非常感謝您的幫助!

回答

0

嗯,我已經想通了 - cell.textLabel坐在我的圖形上,所以模糊了它。我只是將textLabel的backgroundColor屬性設置爲[UIColor clearColor],一切都很好 - 也許我可以讓我的圖形坐在textLabel之上,我還沒有嘗試過。

相關問題