objective-c – 我疯了吗?在10.5中帮助NSFileManager委托方法shouldProceedAfterError

objective-c – 我疯了吗?在10.5中帮助NSFileManager委托方法shouldProceedAfterError,第1张

概述所以我有点像 Cocoa n00b,但是我正在编写这个简单的小程序而且我无法触发NSFileManager委托方法“shouldProceedAfterError …”.这是我在AppDelegate中运行的代码 -(BOOL)copyFile { [[NSFileManager defaultManager] setDelegate:self]; NSError *copyEr 所以我有点像 Cocoa n00b,但是我正在编写这个简单的小程序而且我无法触发NSfileManager委托方法“shouldProceedAfterError …”.这是我在AppDelegate中运行的代码

-(BOol)copyfile {    [[NSfileManager defaultManager] setDelegate:self];    NSError *copyError = nil;    Nsstring *filename = [[Nsstring alloc] initWithString:[[[self.sourcefile path] componentsSeparatedByString:@"/"] lastObject]];    Nsstring *destination = [[[[[UserData sharedData] folderLocation] path] stringByAppendingString:@"/"] stringByAppendingString:filename];    [[NSfileManager defaultManager] copyItemAtPath:[self.sourcefile path] topath:destination error:&copyError];    NSLog(@"error! %@",copyError);    [filename release];    return YES;}- (BOol)fileManager:(NSfileManager *)fileManager shouldProceedAfterError:(NSError *)error copyingItemAtPath:(Nsstring *)srcPath topath:(Nsstring *)dstPath {    NSLog(@"more error... %@",error);    return NO;}- (BOol)fileManager:(NSfileManager *)fileManager shouldcopyItemAtPath:(Nsstring *)srcPath topath:(Nsstring *)dstPath {    NSLog(@"in shouldcopyItemAtPath...");    return YES;}

我正在尝试处理的情况是文件是否已存在于目的地.我确实得到了一个错误,但我从来没有得到“更多错误……”跟踪输出.我也是从shouldcopyItemAtPath得到那个踪迹:所以我不确定为什么这个方法没有被触发?

我疯了,我怎么搞砸这里的委托实施?谢谢你的帮助!

解决方法 这只是一个假设,但由于copyItemAtPath:topath:error被定义为“srcPath中指定的文件必须存在,而dstPath必须在 *** 作之前不存在.”,也许dstPath已存在的场景不被认为是“错误,”因此不会解雇代表.

也许“如果你做了我们告诉你不做的事情,这不是一个错误.”

您可以随时进行检查并自行删除:

NSfileManager* fileManager = [NSfileManager defaultManager];// Delete the file if it already exists.if ([fileManager fileExistsAtPath: destination])        if (![fileManager removeItemAtPath: destination error: error])                return NO;return [fileManager copyItemAtPath: source topath: destination error: error];
总结

以上是内存溢出为你收集整理的objective-c – 我疯了吗?在10.5中帮助NSFileManager委托方法shouldProceedAfterError全部内容,希望文章能够帮你解决objective-c – 我疯了吗?在10.5中帮助NSFileManager委托方法shouldProceedAfterError所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1003612.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存