关于application title一直是untitled的问题

建立了一个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.

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

转载于:https://www.cnblogs.com/aquariusgx/archive/2011/03/17/1986849.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值