removeItemAtPath完成 [英] removeItemAtPath completion
问题描述
我正以这种方式删除路径中的文件:
I am deleting a file at a path in this way:
UIPanGestureRecognizer *gesture = (UIPanGestureRecognizer *)sender;
UIButton *button = (UIButton *)gesture.view;
[[(UIPanGestureRecognizer*)sender view] removeFromSuperview];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *myFilePath = [documentsDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", button.titleLabel.text]];
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:myFilePath error:NULL];
[self ReloadBusinessCards];
然后我调用方法[self ReloadBusinessCards];这将重新加载文件。问题是,它发生删除文件需要很长时间(0.5秒),该方法被调用之前。我想防止这一点,但我不认为这将是一个好主意设置1秒的NSTimer。例如,因为如果应用程序运行速度较慢,文件可以删除更多。是否有一种方法在文件被删除时通知您?
then I am calling the method [self ReloadBusinessCards]; which reloads the files. The problem is that it happens that deleting the file takes a long time (0.5 sec.) and the method is called before. I would like to prevent this, but i don't think it would be a good idea to set an NSTimer of 1 sec. for example because if the app runs slower the file could be deleted after more. Is there a method that notifies you when the file is deleted?
推荐答案
您可以等待操作完成使用
You can wait until the operation is complete using
[receiver performSelectorOnMainThread:@selector(sel)withObject:nil waitUntilDone:NO]
或使用GCD与完成处理程序来验证擦除过程是否实际完成
or use the GCD with a completion handler to verify that the process of erase is actually done
这篇关于removeItemAtPath完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!