隐藏或删除uitableview中的部分

iCo*_*r86 6 iphone uitableview

我正在我的应用程序中实现一个分组表视图,用户可以从表的不同部分选择行.

我想根据第一部分行的选择隐藏(删除)特定部分(包括标题).

第一节标题是"你有车吗?",在行选择中答案是YES或NO.如果用户选择NO,则分组表中的第二和第三部分应隐藏(删除).

对于分组表中的无线电选择,我实现了这一点

我也提到这个,但没有完全满足我的需要.

请帮忙.

编辑

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];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我如何从表中删除部分的代码,myIndexPath是NSIndexPath变量,它指向当前选中的部分.

[table beginUpdates];
[myArray removeObjectAtIndex:myIndexPath.section];
[table deleteSections:[NSIndexSet indexSetWithIndex:myIndexPath.section] withRowAnimation:YES];
[table endUpdates];
Run Code Online (Sandbox Code Playgroud)

iCo*_*r86 9

我解决了我的问题.

[table beginUpdates];
[myArray removeObjectAtIndex:myIndexPath.section];
[table deleteSections:[NSIndexSet indexSetWithIndex:myIndexPath.section] withRowAnimation:UITableViewRowAnimationRight];
[table endUpdates];
Run Code Online (Sandbox Code Playgroud)

"第0节中的行数无效"中的问题.更新后的现有部分中包含的行数(2)必须等于更新前该部分中包含的行数(3)"我忘记了错误从myArrayAnswerCount数组中删除对象.

所以最后关注代码

[table beginUpdates];
[myArray removeObjectAtIndex:myIndexPath.section];
[myArrayAnswerCount removeObjectAtIndex:myIndexPath.section]; //this is what i forgot.
[table deleteSections:[NSIndexSet indexSetWithIndex:myIndexPath.section] withRowAnimation:UITableViewRowAnimationRight];
[table endUpdates];
Run Code Online (Sandbox Code Playgroud)

谢谢.