2014-04-24 86 views
0

我從tableview隨機插入和刪除行。但是,如果我想要刪除的行不在視圖中,那麼在給定行重新開始查看時,它們實際上並未在UI中被刪除。TableView更新沒有發生

如果我只在可見行上添加和刪除行,它工作得很好。什麼可能導致這個問題?

- (void)sectionHeaderView:(BaseSectionHeaderView *)sectionHeaderView sectionOpened:(NSInteger)sectionOpened { 
    LogInfo(@"opening section:%ld",sectionOpened); 
    [_dataSource setSectionAtIndex:sectionOpened Open:YES]; 

    /* 
    Create an array containing the index paths of the rows to insert: These correspond to the rows for each quotation in the current section. 
    */ 

    NSInteger countOfRowsToInsert = [_dataSource tableView:_tableView numberOfRowsInSection:sectionOpened]; 
    NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init]; 
    for (NSInteger i = 0; i < countOfRowsToInsert; i++) { 
     [indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:sectionOpened]]; 
    } 

    /* 
    Create an array containing the index paths of the rows to delete: These correspond to the rows for each quotation in the previously-open section, if there was one. 
    */ 
    NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init]; 
    if (self.openSection.openSectionHeaderView != nil) { 


     [_openSection.openSectionHeaderView toggleOpenWithUserAction:NO]; 
     //  NSInteger countOfRowsToDelete = [_purchaseInvoiceListTable.tableView numberOfRowsInSection:self.openSection.openSectionIndex]; 
     NSInteger countOfRowsToDelete = [_dataSource tableView:_tableView numberOfRowsInSection:self.openSection.openSectionIndex]; 
     [_dataSource setSectionAtIndex:self.openSection.openSectionIndex Open:NO]; 
     for (NSInteger i = 0; i < countOfRowsToDelete; i++) { 
      [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:self.openSection.openSectionIndex]]; 
     } 

    } 


    // style the animation so that there's a smooth flow in either direction 
    UITableViewRowAnimation insertAnimation; 
    UITableViewRowAnimation deleteAnimation; 
    if (self.openSection.openSectionHeaderView == nil || sectionOpened < self.openSection.openSectionIndex) { 
     insertAnimation = UITableViewRowAnimationTop; 
     deleteAnimation = UITableViewRowAnimationBottom; 
    } 
    else { 
     insertAnimation = UITableViewRowAnimationBottom; 
     deleteAnimation = UITableViewRowAnimationTop; 
    } 


    // apply the updates 
    [_tableView beginUpdates]; 
    [_tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:insertAnimation]; 
    [_tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation]; 
    [_tableView endUpdates]; 

    self.openSection.openSectionIndex = sectionOpened; 
    self.openSection.openSectionHeaderView = sectionHeaderView; 
    self.openSection.sectionHeight = [NSNumber numberWithFloat:sectionHeaderView.frame.size.height]; 
    LogInfo(@"sectionOpened:%ld",sectionOpened); 
} 

回答

0

我認爲你應該重新加載此表視圖...

[tableView reloadData]; 

,如果從這個它不會產生預期的結果,那麼刪除陣列,填補表視圖的列的對象。我認爲這一定會工作...

告訴我它是否在工作或...

+0

它不工作 –