2013-07-28 53 views
3

我有一個靜態tableview是使用storyboard設計的。每當我選擇一個單元格並調用reloadSections:withRowAnimation:它會導致它上面的兩個單元格消失,但顯示它應該的4個單元格。有人知道爲什麼會發生這種情況?iOS的UITableView行在reloadSections上消失:withRowAnimation

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

if (indexPath.section == 1) { 
     if (indexPath.row == 0) { 

     } 
     else if (indexPath.row == 1) { // Map Type Cell 

      self.isSelectingMapType = ![self isSelectingMapType]; 
      [self.tableView beginUpdates]; 
      [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationAutomatic]; 
      [self.tableView endUpdates]; 
     } 
     else { 

      // Configure the single selection 
      if (self.checkedIndexPath) { 
       UITableViewCell *uncheckCell = [tableView cellForRowAtIndexPath:self.checkedIndexPath]; 
       uncheckCell.accessoryType = UITableViewCellAccessoryNone; 
      } 

      // Check the cell 
      UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
      cell.accessoryType = UITableViewCellAccessoryCheckmark; 

      // Store the new indexPath 
      self.checkedIndexPath = indexPath; 

      // Save the map type indexPath 
      [LBSettings saveObject:indexPath forKey:kLBSettingsMapTypeIndexPath]; 

      // Save the map type 
      if (indexPath.row == 2) { 

       // Save the map type standard 
       [LBSettings saveObject:[NSNumber numberWithInt:kGMSTypeNormal] forKey:kLBSettingsMapType]; 
      } 
      if (indexPath.row == 3) { 

       // Save the map type satellite 
       [LBSettings saveObject:[NSNumber numberWithInt:kGMSTypeSatellite] forKey:kLBSettingsMapType]; 
      } 
      if (indexPath.row == 4) { 

       // Save the map type hybrid 
       [LBSettings saveObject:[NSNumber numberWithInt:kGMSTypeHybrid] forKey:kLBSettingsMapType]; 
      } 
      if (indexPath.row == 5) { 

       // Save the map type terrian 
       [LBSettings saveObject:[NSNumber numberWithInt:kGMSTypeTerrain] forKey:kLBSettingsMapType]; 
      } 

      self.isSelectingMapType = ![self isSelectingMapType]; 
      [self.tableView beginUpdates]; 
      [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationAutomatic]; 
      [self.tableView endUpdates]; 
     } 
    } 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in each section 
    switch (section) { 
     case 0: 
      return 3; 
      break; 
     case 1: 
      if (self.isSelectingMapType == YES) { 
       return 6; 
      } 
      return 2; 
      break; 
     case 2: 
      return 2; 
      break; 
     case 3: 
      return 6; 
      break; 
     case 4: 
      return 0; 
      break; 
     default: 
      break; 
    } 
    return 0; 
} 

回答

2

嘗試在動畫事務完成後調用reloadData。

[CATransaction begin]; 

[CATransaction setCompletionBlock:^{ 
    [self.tableView reloadData]; 
}]; 

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationAutomatic]; 

[CATransaction commit]; 
相關問題