我在表视图单元格中使用动画...当单元格完全可见时,动画工作正常.如果当时任何单元格部分可见由于动画我的应用程序在行[_Mytableviewobject endUpdates]中崩溃了;
崩溃日志=因未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'单元格动画停止分数必须大于开始分数'
代码部分:
-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionOpened:(NSInteger)sectionOpened
{
//ENSLog(self, _cmd);
[_caseTable reloadData];
NSInteger countOfRowsToInsert = 1;
SectionInfo *sectionInfo = [self.sectionInfoArray objectAtIndex:sectionOpened];
sectionInfo.open = YES;
NSMutableArray *indexPathsToInsert = [[[NSMutableArray alloc] init] autorelease];
for (NSInteger i = 0; i < countOfRowsToInsert; i++)
{
[indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:sectionOpened]];
}
NSMutableArray *indexPathsToDelete = [[[NSMutableArray alloc] init] autorelease];
NSInteger previousOpenSectionIndex = self.openSectionIndex;
if (previousOpenSectionIndex != NSNotFound)
{
SectionInfo *previousOpenSection = [self.sectionInfoArray objectAtIndex:previousOpenSectionIndex];
previousOpenSection.open = NO;
[previousOpenSection.headerView toggleOpenWithUserAction:NO];
NSInteger countOfRowsToDelete = 1;
for (NSInteger i = 0; i < countOfRowsToDelete; i++)
{
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];
}
}
// Style the animation so that there's a smooth flow in either direction.
UITableViewRowAnimation insertAnimation;
UITableViewRowAnimation deleteAnimation;
if (previousOpenSectionIndex == NSNotFound || sectionOpened < previousOpenSectionIndex)
{
insertAnimation = UITableViewRowAnimationTop;
deleteAnimation = UITableViewRowAnimationBottom;
}
else
{
insertAnimation = UITableViewRowAnimationTop;
deleteAnimation = UITableViewRowAnimationTop;
}
// Apply the updates.
[_caseTable beginUpdates];
[_caseTable deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation];
[_caseTable insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:insertAnimation];
[_caseTable endUpdates];
//ExNSLog(self, _cmd);
self.openSectionIndex = sectionOpened;
//ExNSLog(self, _cmd);
}
-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionClosed:(NSInteger)sectionClosed
{
//ENSLog(self, _cmd);
SectionInfo *sectionInfo = [self.sectionInfoArray objectAtIndex:sectionClosed];
sectionInfo.open = NO;
NSInteger countOfRowsToDelete = [_caseTable numberOfRowsInSection:sectionClosed];
if (countOfRowsToDelete > 0)
{
NSMutableArray *indexPathsToDelete = [[[NSMutableArray alloc] init] autorelease];
for (NSInteger i = 0; i < countOfRowsToDelete; i++)
{
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:sectionClosed]];
}
[_caseTable deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
}
self.openSectionIndex = NSNotFound;
//ExNSLog(self, _cmd);
}
Run Code Online (Sandbox Code Playgroud)
小智 44
在尝试使用虚拟页脚删除潜在的"空"表格视图单元格时,我遇到了同样的崩溃.
解决方案是摆脱
tableView:viewForFooterInSection:
tableView:heightForFooterInSection:
Run Code Online (Sandbox Code Playgroud)
并在viewDidLoad中用以下内容替换它们:
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
Run Code Online (Sandbox Code Playgroud)
它似乎发生在设置时 tableview
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
而tableview风格设置Plain而不是Grouped风格
在ios 7更新后我遇到了同样的问题:在我的表视图中,在"deleteRowsAtIndexPaths"中出现崩溃以进行展开/折叠.
令人惊讶的是,我通过使用heightForHeaderInsection而不是heightForFooterInSection解决了这个问题.
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 1; // it was 0 before the fix
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0; // it was 1 before the fix
}
已报告此问题(https://devforums.apple.com/message/795349).
| 归档时间: |
|
| 查看次数: |
9478 次 |
| 最近记录: |