【发布时间】:2011-06-27 07:20:32
【问题描述】:
我在我的应用程序中实现了一个分组表视图,用户可以从表的不同部分选择行。
我想根据第一部分的行选择隐藏(删除)特定部分(包括标题)。
即
第一部分的标题是“你有车吗?”,在行选择中答案是“是”或“否”。 如果用户选择否,则分组表中的第二和第三部分应隐藏(删除)。
对于分组表中的单选,我实现this
我也参考了this,但没有完全满足我的需求。
请帮忙。
编辑
TableViewDelegates
myArray 是我的数据源。 myArrayAnswerCount 包含每个部分的行数计数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [myArray count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
for (int i = 0; i<[myArray count]; i++) {
if (section==i) {
return [[myArray objectAtIndex:i] title];
}
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
for (int i = 0; i<[myArray count]; i++) {
if (section==i) {
return [[myArrayAnswerCount objectAtIndex:i] intValue];
}
}
}
这是我如何从表中删除部分的代码, myIndexPath 是 NSIndexPath 变量,它指向当前选择的部分。
[table beginUpdates];
[myArray removeObjectAtIndex:myIndexPath.section];
[table deleteSections:[NSIndexSet indexSetWithIndex:myIndexPath.section] withRowAnimation:YES];
[table endUpdates];
【问题讨论】:
标签: iphone uitableview