When going through some sample code, notice that setting the main Window Title in IB has no effect when the “create document-based application” option is chosen. The Window would come out with “Untitled” as its title. And we need to override – (NSString *) displayName {} in MyDocument : NSDocument inorder to set the window title. Just wish that some experts in xcode can explain why this is so. That is, what is added to the system when we check the “create document-based application” option when the project is initially generated ?
When going through some sample code, notice that setting the main Window Title in
Share
Understand that when you create a project from a template in Xcode, Xcode doesn’t really generate any code. Sure, it might fill in a few blanks with your name, your project name, etc. But what you’re getting is essentially canned starter code for the type of project you’ve chosen. What’s being added when you check the ‘document based’ option is a NSDocument subclass customized with a reasonable name for your app.
Take a look at Apples “Human Interface Guidelines”, such as this, and you’ll see that document windows are supposed to be titled based on the document that they’re displaying. For that reason, the default behavior for a document-based application is to set the title to the filename of the document file.
Finally, look at the reference page for NSDocument and you’ll find that the behavior you’re seeing is part of the NSDocument class. In particular, if you look at the -displayName method, you’ll find information about how to properly customize the window title.