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, t开发者_StackOverflow社区he 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..
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.
you have created a document based Cocoa application. For new documents, Cocoa sets the proposed name of the document to 'Untitled'.
That's because you checked Create Document-Based Application when you created this project:
You can remove it from info.plist
by clicking the - button next to Document types:
Type in your own title in Storyboard and check the window to "is Inital Controller". After you run your project again, it will be OK.
Do you mean the application menu title? That is changed to match the name of the application at runtime. The simplest way to change it would be to change the Product Name build setting on your target in Xcode.
- (NSString *)displayName
{
NSMutableString *displayName = [NSMutableString stringWithString:[super displayName]];
if ([self fileURL] == nil) {
NSString *firstCharacter = [[displayName substringToIndex:1] lowercaseString];
[displayName deleteCharactersInRange:NSMakeRange(0, 1)];
[displayName insertString:firstCharacter atIndex:0];
}
return [NSString stringWithString:displayName];
}
精彩评论