2015-07-18 93 views
-1

我有一个问题,在加载时tableView中的所有单元格都是重复的。我如何防止这种情况?代码如下:UITableView重复每个单元格

- (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

您可能会将数据添加到您的数据源politicianDetails两次。尝试NSLog(@"Datasource %@", self.politicianDetails);并确保没有重复。如果有,请检查您的代码是否正在保存数据,并确保您没有添加两次。

+0

是的,它是愚蠢的对不起:) – ch1pa

+0

没有问题! – SFF