@AquariusGX

QQ:651572770 加我请注明来意。 twitter: @aquariusgx

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
建立了一个cocoa application项目,在Interface Builder中修改了title,在运行时标题始终是“Untitled”。

这是我在http://stackoverflow.com/questions/4720030/cocoa-mac-application-title-says-untitled上找的解决方法。

I have created a document based Mac OSX application, and when I'm editing in Interface Builder, the title is correct (I filled out that portion of the inspector) but once the program runs, the application title is 'Untitled'. How can I change it? In my IB Doc Window, I have instances of Files Owner, First Responder, NSApplication, and NSWindow. There is no view controller, is that the issue? I'm new to Cocoa..

-> It will probably change to the name of your document once you save it (or open one). – zneak Jan 18 at 3:07

-> Naming a new, unsaved document “untitled” is the correct way according to the HIG. http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGWindows/XHIGWindows.html#//apple_ref/doc/uid/20000961-CHDHBCGE Why do you want to violate that convention? – Peter Hosey Jan 18 at 5:17

下面是比较暂时比较好的解决方法:覆盖NSDocument的-displayName方法

One solution is to override -displayName in your NSDocument subclass:

- (NSString *)displayName {
    if (![self fileURL])
        return @"Some custom untitled string";

    return [super displayName];
}


You can also check out NSWindowController's -windowTitleForDocumentDisplayName: if you're using custom window controllers.

如果有好的建议,欢迎提供,多谢~

posted on 2011-03-17 11:26  aquariusgx  阅读(750)  评论(0编辑  收藏  举报