您知道在表格进入编辑模式后如何让某些单元格出现在表格视图中吗?就像您编辑联系人时“通讯录”iPhone 应用程序所做的那样。
也许我错了,但是在编辑联系人时,看起来像是使用了分组的 UITableView。
我试过这个:
[self.tableView setEditing:YES animated:YES];
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationBottom];
我的表在不编辑时只有 1 个部分,我想在编辑时添加一个额外的部分(以保持简单),但是上面对“insertSections”的调用崩溃了(我的所有表代表都很好地考虑了 1 或 2 个部分)根据 self.editing,我尝试在正常模式下显示两个部分,并且效果很好)
对于“numberOfSectionsInTableView”我有:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (!self.editing) return 1;
return 2;
}
tableView的编辑状态是在哪里进入的?你应该在 -[UINavigationController setEditing:animated:] 中执行此操作:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
if(editing){
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationBottom];
} else {
// delete section
}
}
因此,不要在 tableView 上调用 setEditing,而是在 navigationController 上调用它(可能是self
) 然后控制器将处理编辑模式。
所以controller有编辑模式,tableView也有。一旦以编程方式设置,或者当用户滑动删除行时,tableView 将处于编辑模式。在后一种情况下,控制器 is not在编辑模式下,但是表视图 is.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)