이 문제에 대해 이미 몇 가지 질문이 있지만 내 문제를 해결할 수 없습니다. 문제는 내가 스크롤하거나 내 UITableView 다시로드 할 때 셀을 중복합니다. 문제는 세포 재사용과 관련이 있다는 것을 알고 있습니다. 나는 정의 셀에 대한 XIB를 사용스크롤 한 후 UITableViewCell이 복제됩니다.
- (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;
}
:
내가 셀의 모양을 사용자 정의하는 데 사용하는 코드입니다 : 여기에 잘못 무슨 일이 일어나고 있는지의 스크린 샷입니다 .
누군가 나를 도울 수 있기를 바랍니다.
EDIT : 이것은 데이터가 행에 적용 할 setDiv 메소드에 대한 코드
이다
-(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];
}
setDiv 메소드에서 이미 셀에있는 것이 있으면 제거하십시오. 또한 왜 당신은 두 번 dequeueing입니까? –
'setDiv' 또는 그것이 호출하는 메소드에 대한 코드를 보여줍니다. 당신은 setDiv 메서드 또는 유사한 테이블 뷰 셀에 하위 뷰를 추가하는 것처럼 보입니다. –
'[cell setDiv : div];에 서브 뷰 ('UILabel')를 추가하지 않으시겠습니까? –