我想根据用户的选择从表视图中删除多行。显然我不能使用didSelectRowAtIndexPath
方法,因为它将为所选的每一行调用。我想让用户选择多行进行删除,然后一次性删除它们。是否可以?
如果是,那么该怎么办呢?另外,我正在使用基于单视图的项目,当用户想要从视图中删除行时,我希望在同一视图上将表视图的标题更改为“删除”。
你可以这样做:
- (void)tableView:(UITableView *)theTableView
didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath {
[theTableView deselectRowAtIndexPath:[theTableView indexPathForSelectedRow] animated:NO];
UITableViewCell *cell = [theTableView cellForRowAtIndexPath:newIndexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[selectedCellsMutableArray addObject:newIndexPath];
} else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
[selectedCellsMutableArray removeObjectIdenticalTo:newIndexPath];
}
}
当用户按下删除所选按钮 - 只需调用类似的东西
// change your model here and then:
[yourView deleteRowsAtIndexPaths:selectedCellsMutableArray
withRowAnimation:UITableViewRowAnimationRight];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)