所以我有点像 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:©Error];
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: 获得了该跟踪:所以我不确定为什么该方法没有触发?
我要疯了,我是如何在这里搞砸委托实现的?谢谢你的帮助!