2011-07-13 10 views
0

セルの右側にcell.textLabelを使用してテキストを入力し、セルの右側に小さな「tick」グラフィックを配置するという奇妙な問題が発生しました。セルを選択すると、ティックが表示されるはずです。既に表示されている場合は消えます。実際に何が起こるかは、ティックが現れてからすぐに再び消えていくことです。それはすべてかなり標準的なコードなので、誰が何が起こっているのか分かっていれば、私は喜んで聞くことができます!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の上に置くことができたかもしれませんが、まだ試していません。

関連する問題