iOSUITableView的Edit删除行方法
(在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];
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。