我遇到了一个问题,即tableView中的所有单元格在加载时都是重复的。我该如何防止这种情况?代码如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
PoliticianDetailsD *politician =[self.politicianDetails objectAtIndex:indexPath.row];
if ((NSString *)[NSNull null] == politician.first_name) {
cell.textLabel.text = [NSString stringWithFormat:@"%@", politician.last_name];
}
else if ((NSString *)[NSNull null] != politician.first_name) {
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", politician.first_name, politician.last_name];
}
return cell;
}
答案 0 :(得分:0)
您可能需要两次向数据源politicianDetails
添加数据。尝试NSLog(@"Datasource %@", self.politicianDetails);
并确保没有重复。如果有,请检查您的代码是否正在保存数据,并确保您没有添加两次。