标签:
(在navigationbar上添加的Edit)
//编辑---完成
-(void)bianji{
if (self.tableView.isEditing==NO) {
[self.tableView setEditing:YES animated:YES];
UIImage *imagetmp=[UIImage imageNamed:@"baoxun_01.png"];
[self.btn setImage:imagetmp forState:UIControlStateNormal];
} else {
[self.tableView setEditing:NO animated:YES];
UIImage *imagetmp=[UIImage imageNamed:@"bianji_01.png"];
[self.btn setImage:imagetmp forState:UIControlStateNormal];
}
[self.tableView reloadData];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//数组里面移除行
[myData removeObjectAtIndex:indexPath.row];
//表视图移除行
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
//删除本地文件如果没有可以去掉下面代码
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *path = [paths objectAtIndex:0];
NSString *filename = [path stringByAppendingPathComponent:@"shoucang.plist"];
NSMutableArray *array = [[[NSMutableArray alloc] initWithContentsOfFile:filename]autorelease];
[array removeObjectAtIndex:indexPath.row];
[array writeToFile:filename atomically:YES];
}
}
标签:
原文地址:http://www.cnblogs.com/huangzs/p/4540489.html