【问题标题】:How to delete a cell in UITableView by using custom button in cell?如何使用单元格中的自定义按钮删除 UITableView 中的单元格?
【发布时间】:2011-02-14 06:15:37
【问题描述】:
【问题讨论】:
标签:
iphone
cocoa-touch
uitableview
【解决方案1】:
当我这样做时,我得到了解决方案。
-(void)deleteClicked:(id)sender
{
UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
clickedButtonPath = [self.tableView indexPathForCell:clickedCell];
NSArray *arrayDelete = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryD = [arrayDelete objectAtIndex:0];
NSDictionary *dictOfplist1 = [contentArray objectAtIndex:clickedButtonPath.row];
//To remove the videos from Documents folder
NSString *pathTemp1 = [documentsDirectoryD stringByAppendingString:[dictOfplist1 objectForKey:@"fileVideoE"]];
BOOL succeed1 = [[NSFileManager defaultManager] removeItemAtPath:pathTemp1 error:nil];
//To remove the images shown in cell from Documents folder.
NSString *pathTemp2 = [documentsDirectoryD stringByAppendingString:[dictOfplist1 objectForKey:@"fileImageE"]];
BOOL succeed2 = [[NSFileManager defaultManager] removeItemAtPath:pathTemp2 error:nil];
//To remove the data from the plist which is in Documents folder.
NSString *pathDelete = [documentsDirectoryD stringByAppendingString:@"/details.plist"];
[contentArray removeObjectAtIndex:[clickedButtonPath row]];
[contentArray writeToFile:pathDelete atomically: YES];
//To reload the data of the plist after deleting the items from it.
[self.tableView reloadData];
}
一切都很好,删除了单元格,删除了 plist 中的数据,删除了 Documents 文件夹中的视频和图像。
这是我删除第二行时的图像。
谢谢。
alt text http://www.freeimagehosting.net/uploads/f3c96ae3a7.png
【解决方案3】:
呼叫:
[self.tableView reloadData];
你需要对 MVC 习语做一些研究。