我只知道第一步是检查一行。接下来,我认为是使用一个NSMutableArray
来记录检查了哪一行,这是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[tableView cellForRowAtIndexPath:indexPath] accessoryType] == UITableViewCellAccessoryCheckmark){
[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryNone];
}
else {
[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
}
}
所以,我的问题是:
发布于 2010-09-20 04:33:05
首先,在viewController的NSMutableArray文件中声明一个.h。
就像这样:
NSMutableArray *checkedRows;
更改您的didSelectRow方法如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([checkedRows containsObject:indexPath]) {
[checkedRows removeObject:indexPath];
}
else {
[checkedRows addObject:indexpath];
}
[self.tableView beginUpdates]; //Just for animation..
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
}
在您的cellForRow方法中添加以下内容:
if ([checkedRows containsObject:indexPath]){
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
发布于 2010-09-20 04:35:29
你搞错了。
你自己不处理编辑附件视图。相反,将setEditing:animated:
发送到表中,它会为您更改单元格。然后,您需要实现:
– tableView:commitEditingStyle:forRowAtIndexPath:
– tableView:canEditRowAtIndexPath:
..。实际删除行单元格。
https://stackoverflow.com/questions/3751273
复制相似问题