如何使用自定义按钮在单元格中删除UITableView中的单元格? [英] How to delete a cell in UITableView by using custom button in cell?

查看:122
本文介绍了如何使用自定义按钮在单元格中删除UITableView中的单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有UITableView。我定制了单元格的高度(80.0f)。

I have UITableView. I customized the cell height (80.0f).

我有4个标签(UILabel)和1个图像(UIImage)和3个按钮(UIButton)。一个按钮是删除按钮。通过触摸图像上的单元格或按钮(播放按钮),视频将被加载并播放。

I have 4 labels(UILabel) and 1 image(UIImage) and 3 buttons (UIButton). one of the button is delete button. By touching the cell or button(play button) on the image a video is loaded and played.

我需要通过触摸删除按钮删除单元格。
我为删除按钮写了一个选择器。我可以从媒体库中删除视频。但是如何从表中删除单元格?

I need to delete the cell by touching delete button. I wrote a selector for delete button. I can delete the video from the library. But how to delete the cell from the table ?

谢谢。
下面的图片显示了我的程序的删除按钮。

Thank you. The following image shows the delete button of my program.

推荐答案

-(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中的数据被删除文档文件夹中的视频和图像将被删除。

Every thing was fine the cell is removed, the data in the plist is removed the videos and images in Documents folder are removed.

这是删除第2行时的图片。

谢谢。

Here is the image when I delete the 2nd row.
Thank You.

这篇关于如何使用自定义按钮在单元格中删除UITableView中的单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆