gpt4 book ai didi

iphone - 当我们重用单元格标识符时,UItableview 标题闪烁

转载 作者:行者123 更新时间:2023-12-03 19:02:27 26 4
gpt4 key购买 nike

我使用以下命令创建了一个单元格

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 =@"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;

}

但是,当我快速滚动表格时,标题几乎在所有情况下都会闪烁。如何防止这种闪烁?

最佳答案

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

关于iphone - 当我们重用单元格标识符时,UItableview 标题闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1944294/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com