2014-09-06 92 views
0

我有一個最初沒有數據的表格,並顯示一條消息,指出用戶沒有要顯示的數據。上一個單元格不會在UITableView中消失

我有一個方法被調用viewDidLoad並重新加載表數據。發生這種情況時,仍會顯示第一個表格單元格,其餘單元格會顯示正確的數據。第一個單元仍然顯示空的數據信息。有什麼我在這裏失蹤?下面我有我的cellForRowAtIndexPath方法。

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView { 
    static NSString *CellIdentifier = @"TableViewCell"; 
    static NSString *CellIdentifierEmpty = @"TableViewCellEmpty"; 

    if ([[self.fetchedResultsController.sections objectAtIndex:indexPath.section] numberOfObjects] == 0) { 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierEmpty]; 
     if(cell == nil) { 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifierEmpty]; 
      cell.backgroundColor = [UIColor whiteColor]; 
      cell.textLabel.textColor = [UIColor blackColor]; 

      cell.detailTextLabel.numberOfLines = 0; 
      cell.detailTextLabel.lineBreakMode = NSLineBreakByWordWrapping; 
      cell.detailTextLabel.textColor = [UIColor blackColor]; 
      cell.tag = -1; 
     } 
     return [self setTextForEmptyCell:cell]; 
    } 

    MyObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (!cell) { 
     cell = // Set values 
    } 
    // Set cell details   
    return cell; 
} 
+0

當你沒有任何數據時,爲什麼不在你的tableView中添加一個簡單的'UILabel',並根據數據的可用性切換它的'hidden'狀態?添加到表格視圖的任何視圖都會隨之滾動,並且會給出標籤在單元格內的**外觀**。這不能回答你的問題,但它確實解決了你的問題。此外,您避免創建第二種類型的單元格。 – n00bProgrammer 2014-09-06 07:04:57

+0

那就是我最終做的。但這不是正確的解決方案......正確的解決方案是弄清楚爲什麼細胞不會消失。不知道爲什麼......很奇怪。 – KVISH 2014-09-06 20:43:23

回答

0

發現此問題。在使用AFNetworking從服務器獲取數據時,這是一個線程問題。檢查所有使用新線程的塊!

相關問題