Ios TableView更新未发生
我正在从tableview中随机插入和删除行。但是,如果要删除的行不在视图中,则当给定行返回视图时,它们实际上不会在UI中删除 如果我只在可见的行上添加和删除行,它就可以正常工作。是什么导致了这个问题Ios TableView更新未发生,ios,uitableview,Ios,Uitableview,我正在从tableview中随机插入和删除行。但是,如果要删除的行不在视图中,则当给定行返回视图时,它们实际上不会在UI中删除 如果我只在可见的行上添加和删除行,它就可以正常工作。是什么导致了这个问题 - (void)sectionHeaderView:(BaseSectionHeaderView *)sectionHeaderView sectionOpened:(NSInteger)sectionOpened { LogInfo(@"opening section:%ld",sect
- (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);
}
-(void)sectionHeaderView:(BaseSectionHeaderView*)sectionHeaderView sectionOpened:(NSInteger)sectionOpened{
登录信息(@“正在打开的节:%ld”,节已打开);
[_数据源setSectionAtIndex:sectionOpened-Open:YES];
/*
创建一个数组,其中包含要插入的行的索引路径:这些路径对应于当前节中每个引号的行。
*/
NSInteger COUNTOOFROWSTOINSERT=[\u数据源表视图:\u表视图行数节:节打开];
NSMUTABLEARRY*indexPathsToInsert=[[NSMUTABLEARRY alloc]init];
对于(NSInteger i=0;i
我认为您应该通过以下方式重新加载表视图
[tableView reloadData];
如果这样做不会得到预期的结果,则从填充表视图行的数组中删除该对象。我想这肯定会有用的
告诉我它是否有效