Load View/Views from NIB issue

Discussion in 'iOS Programming' started by Sergio10, Sep 10, 2009.

  1. Sergio10 macrumors regular

    Oct 3, 2007

    I need to get from the myxib.xib view/views controls and use it in the AppDelegate.m

    So I use:
    NSArray *xib = [[NSBundle mainBundleloadNibNamed:@"myxib" owner:self options:nil];    
    BUT it crashes(( I attached current simple project: http://www.mediafire.com/download.php?zwam3enynm2

    Please help me. What is wrong?

    Thank you.
  2. wlh99 macrumors 6502

    Feb 7, 2008
    You are trying to assign an NSBundle to an NSArray, and loadNibNamed isn't a method NSBundle knows. Look at the API docs for those classes. Also look at NSViewController

    NSViewController viewController = [[NSViewController alloc] initWithNibName:@"view" bundle:[NSBundle mainBundle]];
  3. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    As wlh99 said, you are trying to call a method on an instance that does not have an instance method of that name. That's never going to work. Based on this and a number of other recent threads of yours, Sergio10, I think you might want to step back from the real coding for a while, go (re)learn the basics of Objective-C and iPhone development, and come back when you are much more comfortable with those.
  4. Sergio10 thread starter macrumors regular

    Oct 3, 2007
    Thanks for:
    NSViewController viewController = [[NSViewController allocinitWithNibName:@"view" bundle:[NSBundle mainBundle]];
    It's works.
    1. what to do when I have two UIView in the bundle(XIB)? How to load the view exactly I need?
    2. Is it possible to avoid of saving controller file(MyController.m) for file's Owner? Because I transfer view only.

    Thank you
  5. wlh99 macrumors 6502

    Feb 7, 2008
    1. The line I gave you creates a view controler and loads the nib. You don't load part of the nib. To do anything with it (like display a view) requires more code and varys depending on what you are doing. It might be one line, and might be several lines and need more controllers.

    2. I don't understand this question. By the way you ask it seems like you really need some fundementals. Any nib file has an owner, the object that loads it. In this case the owner is viewController because the view controller loaded the nib with initWithNibName: The file owner in IB is how Outlets and Actions are created and how viewController "talks" to individual objects in the nib.

    I hope I don't sound rude, but the fastest way to learn this is with some books. Given 1 month per book you would be in good shape in three months. Otherwise you would be asking more and more questions and in 3 months only be more confused.




Share This Page