TableView reloadData不会更新iPad中的UI,但可用于iPhone

问题描述:

我有一个奇怪的错误。我正在使用UITableView,当一行被选中时,必须重新加载它。这在iPhone模拟器中正常工作。在iPad上运行时,didSelectRowAtIndexPath正在调用,但UI没有更新。 我试着在主线程上调用方法reloadData。它仍然是一样的。TableView reloadData不会更新iPad中的UI,但可用于iPhone

我已经尝试了各种解决方案在*。似乎没有什么能解决我的问题。

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

我找到了解决此问题的解决方案。 UITableViewCell的背景颜色设置为清除颜色,UIView的背景颜色也设置为清除颜色。更改这些设置显示在iPad模拟器中插入UITableView中的行。

重新装入表视图委托内部表视图我的代码,在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