最初我需要在 tableview 中列出 3 个项目。
单击其中任何一个时,它会显示另外 3 个项目作为所选主项目的子项目。
我正在使用的数组是
aryTemp = [[NSMutableArray alloc] initWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"YES", @"isExpand", [NSArray arrayWithObjects:@"One",@"Two",@"Three", nil], @"data", nil], nil];
aryTemp1 = [[NSMutableArray alloc] initWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"NO", @"isExpand", [NSArray arrayWithObjects:@"Doc", @"XML", @"PDF", nil], @"data", nil], nil];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int count = 0;
if(!boolIsExpanded)
count = 1;
else {
count = [[[aryTemp objectAtIndex:0] objectForKey:@"data"] count] + [[[aryTemp1 objectAtIndex:0] objectForKey:@"data"] count];
}
return count;
}
-(void)addOrDeleteRows:(NSIndexPath *)indexPath add:(BOOL)aBool
{
NSMutableArray *paths = [[NSMutableArray alloc] init];
if(boolIsExpanded)
{
boolIsExpanded=NO;
for (int i=1; i<=[[[aryTemp1 objectAtIndex:0] objectForKey:@"data"] count]; i++) {
NSIndexPath *indxPath;
indxPath = [NSIndexPath indexPathForRow:(indexPath.row)+i inSection:indexPath.section];
[paths addObject:indxPath];
NSLog(@"paths : %@",paths);
}
intPrevIndex = indexPath.row;
[tblView beginUpdates];
[tblView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationLeft];
[tblView endUpdates];
}
else
{
boolIsExpanded = YES;
for (int i = 1; i <= [[[aryTemp1 objectAtIndex:0] objectForKey:@"data"] count]; i++) {
NSIndexPath *indxPath = [NSIndexPath indexPathForRow:(indexPath.row)+i inSection:indexPath.section];
[paths addObject:indxPath];
}
intPrevIndex = indexPath.row;
[tblView beginUpdates];
[tblView deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationLeft];
[tblView endUpdates];
}
}
这个计算究竟应该如何进行?使用部分时。
插入行后,它调用并在 -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:1037 2012-10-03 11:37:43.955 ExpandRowsSample[1657:f803] 中NumberOfRow
出现错误断言失败并崩溃
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:第 0 节中的行数无效。更新后现有节中包含的行数 (6) 必须等于该节中包含的行数更新前的节 (1),加上或减去从该节插入或删除的行数(0 插入,0 删除),加上或减去移入或移出该节的行数(0 移入,0 移动出去)。' *