Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

john903

macrumors member
Original poster
Apr 11, 2008
66
0
How do you change the the title of the window on the fly? Basically, something like glutSetWindowTitle for a cocoa app.

Also, how to you change the text on the bottom bar of the window?
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
To set the title:

Code:
[myWindow setTitle:@"Whatever you want to call it"];

Not sure what you mean about text at the bottom. Like a status bar? That's not a standard component of a Cocoa window. But you can easily add one, just add a text field at the bottom in Interface Builder and change the text in the text field using:

Code:
[myStatusBarTextView setStringValue:@"Status text here"];

(setStringValue: is a method that NSTextField inherits from NSControl) Make sure you set the text field and any box it's in to stick to the bottom of the frame and expand horizontally with window resizing.
 

john903

macrumors member
Original poster
Apr 11, 2008
66
0
Thank you! That worked.

Is there a way to update the window title from inside an NSDocument?
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
Is there a way to update the window title from inside an NSDocument?

Uhm, yeah. You can update a window's title from anywhere you can get the window object.

In an NSDocument you can get the owning window and change its title using:

Code:
[[self window] setTitle:str];

Where you do it is up to you. There are various methods that get invoked in NSDocument when a document window is created, and it can get more complicated with custom window controllers and so on. So where you do it depends on how you setup the NSDocument-based app.
 

john903

macrumors member
Original poster
Apr 11, 2008
66
0
That's what I had tried but I get a warning,

warning, 'MyDocument' may not respond to '-window'

It compiles and run but doesn't work. Any pointers would be appreciated!
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
The window title of a document window in a document-based app is set automatically (to the name of the associated file) and you cannot set it. -setTitle: is ignored for document windows. If you want to do this you have to subclass NSWindowController and override the -windowTitleForDocumentDisplayName: method. Apple should probably document this right under NSWindow's -setTitle: info...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.