Change Window Title

Discussion in 'Mac Programming' started by john903, May 15, 2008.

  1. john903 macrumors member

    Joined:
    Apr 11, 2008
    #1
    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?
     
  2. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    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.
     
  3. john903 thread starter macrumors member

    Joined:
    Apr 11, 2008
    #3
    Thank you! That worked.

    Is there a way to update the window title from inside an NSDocument?
     
  4. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #4
    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.
     
  5. john903 thread starter macrumors member

    Joined:
    Apr 11, 2008
    #5
    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!
     
  6. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #6
    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...
     

Share This Page