lantianyiming
lantianyiming
2013-07-26 07:46
采纳率: 79.6%
浏览 2.4k
已采纳

滑动手势从tableView删除文件

if (editingStyle == UITableViewCellEditingStyleDelete){
         NSFileManager *fileManager = [[NSFileManager alloc]init];       
         NSString *filePath = [documentsDirectory
         stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ ",[self->localSongs objectAtIndex:indexPath.row]]];        
        [fileManager removeItemAtPath:filePath error:nil]; 
        [self->localSongs removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self.tableView reloadData];
    }

要实现使用滑动手势从TableView删除文件,不从文件目录中

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • xinyoulingxi1_tong
    xinyoulingxi1_tong 2013-07-26 08:48
    已采纳
    NSString *imageName = @"name of your file"
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
    
        [fileManager removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:imageName] error:nil];
    
    点赞 评论

相关推荐