2015-07-18 105 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

相關問題