【发布时间】:2015-11-19 08:10:09
【问题描述】:
我正在使用TQMultistageTableView 库创建一个基于表的应用程序来扩展部分。我的要求是,如果用户将点击表格部分,则部分背景颜色应更改为蓝色,如果未选择/扩展,其余部分背景颜色应为白色。为此,我创建了一个数组来保存节索引,然后我正在重新加载此节。
第一次(当我的数组为零时),它工作正常。但问题是当我的数组中保存了一个部分索引(因为任何一个部分被展开/选择)然后我试图通过重新加载第二部分来扩展其他部分时,它会因以下错误而崩溃:
*** -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:1368 中的断言失败
*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:无效 第 1 节中的行数。包含在第 1 节中的行数 更新后的现有节(0)必须等于 更新之前该部分中包含的行 (3),加号或减号 从该部分插入或删除的行数(0 插入, 0 已删除)加上或减去移入或移出的行数 该部分(0 移入,0 移出)。'
这是我的代码:
//头文件打开方法
- (void)mTableView:(TQMultistageTableView *)mTableView1 willOpenHeaderAtSection:(NSInteger)section
{
NSLog(@"Open Header ----%ld",section);
NSDictionary *selectedSection = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%ld", (long)section] ,@"section" ,nil];
for(int i=0;i<[ selectedArrayForSectionPlus count];i++)
{
if([[[selectedArrayForSectionPlus objectAtIndex:i] objectForKey:@"section"] isEqualToString:[NSString stringWithFormat:@"%ld", (long)section]])
{
[selectedArrayForSectionPlus removeObjectAtIndex:i];
[self.mTableView.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
return;
}
}
[selectedArrayForSectionPlus addObject:selectedSection];
[self.mTableView.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];//here it is crashing
}
//头部关闭方法
- (void)mTableView:(TQMultistageTableView *)mTableView willCloseHeaderAtSection:(NSInteger)section
{
NSLog(@"Close Header ---%ld",section);
for(int i=0;i<[ selectedArrayForSectionPlus count];i++)
{
if([[[selectedArrayForSectionPlus objectAtIndex:i] objectForKey:@"section"] isEqualToString:[NSString stringWithFormat:@"%ld", (long)section]])
{
[selectedArrayForSectionPlus removeObjectAtIndex:i];
[self.mTableView.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
return;
}
}
}
//viewForHeaderInSection 方法
- (UIView *)mTableView:(TQMultistageTableView *)mTableView viewForHeaderInSection:(NSInteger)section;
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.mTableView.frame.size.width, 80)];
for (int i = 0; i<selectedArrayForSectionPlus.count; i++) {
if([[[selectedArrayForSectionPlus objectAtIndex:i] objectForKey:@"section"] isEqualToString:[NSString stringWithFormat:@"%ld", (long)section]])
{
[view setBackgroundColor:[UIColor colorWithRed:0/255.0 green:150/255.0 blue:214/255.0 alpha:1.0]];
}
else
{
[view setBackgroundColor:[UIColor whiteColor]];
}
}
return view;
}
有人知道如何重新加载该部分吗?
感谢您的指点!
【问题讨论】:
标签: ios objective-c iphone uitableview expand