基于文档的QTKit应用程序。保存时,新文件名在活动窗口titleBar中更新。我还想显示新保存的文件名字符串在textField中,在打开的文档中的其他位置。该代码成功保存了新的文档。但lastPathComponent字符串不会更新。请指教?保存后设置lastPathComponent字符串
感谢,
保罗
- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
NSURL *outputFileURL = [(NSURL *)contextInfo autorelease];
if (returnCode == NSOKButton) {
NSString *filename = [sheet filename];
[[NSFileManager defaultManager] moveItemAtPath:[outputFileURL path] toPath:filename error:nil];
NSString *path = [filename lastPathComponent];
[textField setStringValue:[path lastPathComponent]];
[[NSWorkspace sharedWorkspace] openFile:filename];
}
else {
[[NSFileManager defaultManager] removeItemAtPath:[outputFileURL path] error:nil];
}
}
你为什么要实现自救?通常,文档系统会为您处理保存。如果您想要改变它的工作方式,请查看文档控制器的方法,并查看哪些最适合您进行覆盖。 http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSDocumentController_Class/ – 2010-02-23 16:46:44