滚动后 UITableViewCell 被复制 [英] UITableViewCell gets duplicated after scroll

查看:20
本文介绍了滚动后 UITableViewCell 被复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然已经有一些关于这个问题的问题,但我似乎无法解决我的问题.问题是,当我滚动或重新加载 UITableView 时,单元格会重复.我知道这个问题与细胞的重用有关.这是出现问题的屏幕截图:

Although there are some questions already being asked about this problem, I can't seem to fix mine. Problem is that when I scroll or reload my UITableView the cells duplicate. I know the problem has something to do with reusing of the cells. Here's a screenshot of what's going wrong:

http://imgur.com/JrnERSD

这是我用来自定义单元格外观的代码:

Here's the code I use to customize the appearance of the cell:

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

static NSString *cellID = @"DividendCell";

DividendCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

if (cell == nil)
{        
    [tableView registerNib:[UINib nibWithNibName:cellID bundle:nil] forCellReuseIdentifier:cellID];
    cell = [tableView dequeueReusableCellWithIdentifier:cellID];
}

dividend *div = [[[aAgendaItems objectAtIndex:indexPath.section] agendaItems] objectAtIndex:indexPath.row];
[cell setDiv:div];

return cell;

}

我使用 Xib 作为自定义单元格.

I use a Xib for the custom cell.

希望有人能帮帮我!

这是 setDiv 方法将数据应用到行的代码:

This is the code for the setDiv method to apply data to row:

-(void)setDiv:(dividend *)div {
NSString *text = [[NSString alloc] initWithString:[[[div RelatedIssue] ShortName] capitalizedString]];
[issueName setText:text];
[text release];

text = [[NSString alloc] initWithString:[div Description]];
[issueType setText:text];
[text release];

text = [[NSString alloc] initWithString:[div Currency]];
[issueCurrency setText:text];
[text release];

text = [[NSString alloc] initWithString:[super formatDouble:[div BrutValue]]];
[issueKoers setText:text];
[text release];

NSDateFormatter *format = [[NSDateFormatter alloc] init];
NSLocale *loc = [[NSLocale alloc] initWithLocaleIdentifier:@"nl_NL"];
[format setLocale:loc];
[format setDateFormat:@"dd MMM"];

text = [[NSString alloc] initWithString:[format stringFromDate:[div ExDividendDate]]];
[exDividendDate setText:text];
[text release];

NSComparisonResult result = [[div PaymentDate] compare:[NSDate date]];
text = [[NSString alloc] initWithString:[format stringFromDate:[div PaymentDate]]];
if (result==NSOrderedAscending) {
    [exPaymentDate setTextColor:[UIColor darkGrayColor]];
} else {
    [exPaymentDate setTextColor:[UIColor blackColor]];
}
[exPaymentDate setText:text];
[text release];
[loc release];

}

推荐答案

我通过试用 & 设法解决了这个问题错误.解决方案是选中属性检查器视图 > 绘图下的复选框清除图形上下文以获取特定标签.我注意到这个框没有检查相互重叠的标签.真的很奇怪imo.但很高兴我在疯狂一周后修复了它.

I managed to fix the problem by trial & error. The solution was to check the checkbox Clears Graphics Context under View > Drawing in the Attributes Inspector for the specific labels. I noticed this box wasn't checked for the labels that where overlapping each other. Really strange imo. But happy I fixed it after a week of getting crazy.

这篇关于滚动后 UITableViewCell 被复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆