2009-12-22 67 views
5

我创建使用的UITableView头闪烁时,我们重用

static NSString *CellIdentifier = @"TweetListUserName"; 

CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
     cell = [[[CustomTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease] ; 
} 

一个单元格,使用下面的代码来设置一个节头的小区标识:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 

     UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(0.0, -4.0, 320.0, 67.0)]autorelease]; 
     [customView setOpaque:YES]; 
     UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(-2.0, -4.0, 328.0, 67.0)]; 
     [image setImage:[UIImage imageNamed:@"header-msg.png"]]; 
     [image setOpaque:YES]; 
     [customView addSubview:image]; 

     UILabel *label1 =[[UILabel alloc] initWithFrame:CGRectMake(10, 5, 100, 12)]; 
     label1.text [email protected]"TWEETS MATCHING:"; 
     label1.textAlignment=UITextAlignmentLeft; 
     [label1 setTextColor:[UIColor grayColor]]; 
     [label1 setFont:[UIFont fontWithName:@"Helvetica" size:9]];; 
     [label1 setBackgroundColor:[UIColor clearColor]]; 
     [customView addSubview:label1]; 
     [label1 release]; 

     UILabel *label2 =[[UILabel alloc] initWithFrame:CGRectMake(10, 6, 315, 50)]; 
     label2.text =usernametag; 
     label2.textAlignment=UITextAlignmentLeft; 
     [label2 setTextColor:[UIColor blackColor]]; 
     [label2 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]]; 
     [label2 setBackgroundColor:[UIColor clearColor]]; 
     [customView addSubview:label2]; 
     [label2 release]; 


     return customView; 

    } 

然而,当我快速滚动表头几乎在所有情况下闪烁。我怎样才能防止这种闪烁?

回答

0

嗨我想你需要测试它是否已经设置。你现在的方式是每次滚动时都会运行上面的代码,这意味着它会被设置很多。

+0

实际上没有在代码中提到,但我释放自定义视图 – crystal 2009-12-24 06:13:25

+0

这不是该单元格闪烁标题的原因。我知道这是一个古老的问题......但现在发生在我身上。 – Jann 2011-08-10 15:43:27

+0

你是否在重复调用的任何地方调用[tableView reloadData]? – RickiG 2011-08-11 09:46:24

0

我有过类似的问题。

在我的情况下,原因是在自定义表格单元格。 在我的自定义表格单元格中,我使用了一个UITextView对象,其scrollEnabled属性设置为NO,可编辑属性设置为NO。

该probelm被链接到scrollEnabled =否。使用scrollEnabled = YES我没有问题。

然而,因为没有编辑和滚动一个UITextView是不是从一个UILabel太大的不同,我换成一个UILabel设置numberOfLines的UITextView的0

不要问我为什么。它以这种方式表现得很好。 :)