Help with IB document-based app issue please

Discussion in 'Mac Programming' started by HawaiiMacAddict, Jun 13, 2008.

  1. macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #1
    Aloha everyone,

    I am attempting to create a document-based Cocoa app, but am having a major issue with Interface Builder. Once I get the code entered and double-click on MainMenu.xib, all of the IB elements appear on screen with the notable exception of the main window. I therefore can not drop any UI elements on it, such as text fields, buttons, table views, etc... If I Build and Go, however, the window gets called up like normal, except that there are no UI elements on it (because it doesn't appear when IB is invoked).

    I do not have this problem with a "regular" Cocoa app, only with the document-based app. Does anyone know where I can look to find a solution to this rather vexing issue? I'm working my way through Aaron Hillegass' Cocoa Programming for Mac OS X (this is actually my first foray into Mac programming), and can not create the RaiseMan app due to this issue. I've been trying to find a solution to this issue for the past several days and have exhausted all other sources of information. I, therefore, humbly approach everyone here to request assistance. Any and all assistance is greatly appreciated.

    Mahalo in advance,

    :apple:HawaiiMacAddict
     
  2. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    Document-based applications have two nibs by default: MainMenu.nib, and one for the document window, MyDocument.nib. Open MyDocument.nib (or .xib) and you should see the document window object.

    (At least that's the way it is in Tiger)
     
  3. thread starter macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #3
    Aloha HiRez,

    Thanks for your reply. I'll check that out as soon as I get home from work.

    :apple:HawaiiMacAddict
     
  4. thread starter macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #4
    Aloha HiRez,

    I just got home from work, after seeing a couple of movies, and finally noticed the MyDocument.xib file. I double-clicked on that, and the missing document window appeared on screen. Thanks for opening my eyes - I am still very much a noob when it comes to Objective-C and Xcode. Thanks ever so much for pointing me in the right direction.

    HawaiiMacAddict
     
  5. macrumors newbie

    Joined:
    Oct 7, 2008
    #5
    Hi guys,

    I am also new to Objective-C. I have a different issue with the RaiseMan app. I have created the document-based app as per instruction from the book.

    But when I try to build and run, the RaiseMap app just sits in the dock. No UI Window appears. I am not sure why this is happening. I have never had any problems with just standard Cocoa Applications.

    Any help is much appreciated.

    Thanks!
     
  6. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #6
    @HawaiiMacAddict , hey glad I could help!

    @crapzone, some things to check...

    • Open the debugging console in Xcode and see if any errors or messages show up when you run the app (for example, an invalid binding can sometimes cause an app to exit).

    • Do you have a MyDocument.xib file in your project?

    • Did you try to rename your document class or its .xib file at some point? If you did you have to change the name in several places.

    • Open MyDocument.xib. Is there a window in it? Is it connected to File's Owner (your document class) as "window", and is File's Owner connected to it as "delegate"? Both must be connected.

    • View MyDocument.m. Is the -windowNibName method present and does it look like this?
    Code:
    - (NSString *)windowNibName {
        return @"MyDocument";
    }
    
    • Put the line NSLog(@"test"); as the first line in your document's -init method (in MyDocument.m). Does it show up in the debugging console when you run the app? If so, put the line inside -windowControllerDidLoadNib:

    • Check your project settings to make sure they're correct for your processor type and target OS:
    xcode_settings.png
    xcode_settings_2.png
     
  7. macrumors newbie

    Joined:
    Oct 7, 2008
    #7
    Thanks HiRez for your prompt reply and your very detailed analysis of the problem.

    It's working now. The problem was I removed this piece of code from MyDocument.m :

    - (NSString *)windowNibName {
    return @"MyDocument";
    }

    It as auto generated when I created the project. Somehow I stupidly went and deleted those because I thought they were just dummy methods. :p

    Thanks heaps for your help!! Much appreciated! =)

    Cheers!
     
  8. macrumors 6502

    Joined:
    Dec 6, 2006
    #8
    Simple advice for everybody,

    never ever delete any code generated by the project wizards in Xcode, unless you are a wizard yourself.

    You will see that in some programs released today, developers don't even bother changing the name from MyDocument.h and MyDocument.xib, as it can cause massive problems if they forget to change the references anywhere.
     
  9. macrumors newbie

    Joined:
    Oct 7, 2008
    #9
    Thanks mate! I'll definitely keep that in mind :>
     

Share This Page