2016-05-14 42 views
0

我有一個奇怪的錯誤。我正在使用UITableView,當一行被選中時,必須重新加載它。這在iPhone模擬器中正常工作。在iPad上運行時,didSelectRowAtIndexPath正在調用,但UI沒有更新。 我試着在主線程上調用方法reloadData。它仍然是一樣的。TableView reloadData不會更新iPad中的UI,但可用於iPhone

我已經嘗試了各種解決方案在stackoverflow。似乎沒有什麼能解決我的問題。

UPDATE

當我選擇的小區,新的小區將被添加。所以我需要重新加載我的tableview來顯示動態變化。 發佈以下

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath 
{ 
NSUInteger count=indexPath.row+1; 

NSMutableArray *insertIndexPaths = [NSMutableArray array]; 

[insertIndexPaths addObject:[NSIndexPath indexPathForRow:count inSection:indexPath.section]]; 

switch (indexPath.row) { 
     case 0: 
    { 
    if ([ItemsInSection[indexPath.section] count]==1){ 
       [ItemsInSection[indexPath.section] addObject:obj2]; 

       [TabView beginUpdates]; 
       [TabView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft]; 

       [TabView endUpdates];   
      } 
      else { 

       [ItemsInSection[indexPath.section] removeAllObjects]; 
       [ItemsInSection[indexPath.section] addObject:obj1]; 

       [self.TabView reloadData]; 

      } 
     } 
      break; 

     case 1: 

    {if ([ItemsInSection[indexPath.section] count]==2){ 
       [ItemsInSection[indexPath.section] addObject:obj3]; 

       [self.TabView beginUpdates]; 
       [TabView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft]; 
       [self.TabView endUpdates]; 

      } 
      else 
      { 
       [ItemsInSection[indexPath.section] removeAllObjects]; 
       [ItemsInSection[indexPath.section] addObject:obj1]; 
       [ItemsInSection[indexPath.section] addObject:obj2]; 

       [self.TabView reloadData]; 
       } 
     } 
      break; 

     case 2: { 

      if ([ItemsInSection[indexPath.section] count]==3) { 
       [ItemsInSection[indexPath.section] addObject:obj4]; 
       [self.TabView beginUpdates]; 
       [TabView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft]; 
       [self.TabView endUpdates]; 

      } 
      else 
      { 
       [ItemsInSection[indexPath.section] removeObject:obj4]; 
       [self.TabView beginUpdates]; 
       [TabView deleteRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft]; 

       [self.TabView endUpdates]; 

      } 
      } 
      break; 

        default: 
      break; 
    } 

} 
+2

你應該發佈你的代碼。聽起來這個問題在別的地方。此外,當你選擇一個單元格時,爲什麼要重新加載整個表格視圖?請描述你正在努力實現的實際目標,而不是尋找解決方案來解決你的未嘗試的嘗試。 – ozgur

回答

0

我找到了解決此問題的解決方案。 UITableViewCell的背景顏色設置爲清除顏色,UIView的背景顏色也設置爲清除顏色。更改這些設置顯示在iPad模擬器中插入UITableView中的行。

2

重新裝入表視圖委託內部表視圖我的代碼,在tableview中選擇委託方法都有其相關的選擇動畫過程。所以我會建議你移動這個方法內的所有代碼來分離方法。並調用該方法。

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{ 
      [self.aiTableView beginUpdates]; 
      // your table view selection code 
      [self.aiTableView endUpdates]; 
    }); 
+0

這不能解決我的問題。 NumberOfRowsInSection方法返回no.of行。但它沒有被插入到UITableView中。這隻發生在iPad中。我的原始代碼在iPhone中運行良好。我想知道可能是什麼問題 – user5553647

+0

請將我的所有代碼從dispatch_after()中移入dispatch_async(dispatch_get_main_queue(),^ {}); ,請確保您在表格視圖中委託選擇方法時調用此代碼塊。 – kaushal

+0

我不確定iPhone和iPad的代碼行爲。 :) – kaushal

相關問題