Load View/Views from NIB issue

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

  1. Sergio10 macrumors regular

    Joined:
    Oct 3, 2007
    #1
    Hello,

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

    So I use:
    PHP:
    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

    Joined:
    Feb 7, 2008
    #2
    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

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

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    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

    Joined:
    Oct 3, 2007
    #4
    Thanks for:
    PHP:
    NSViewController viewController = [[NSViewController allocinitWithNibName:@"view" bundle:[NSBundle mainBundle]];
    It's works.
    BUT:
    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

    Joined:
    Feb 7, 2008
    #5
    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.

    http://www.amazon.com/Programming-Objective-C-Stephen-Kochan/dp/0672325861

    http://www.amazon.com/Cocoa-Programming-Mac-OS-3rd/dp/0321503619/ref=pd_sim_dbs_b_4

    http://www.amazon.com/Beginning-iPhone-Development-Exploring-BEGINNING/dp/B001TM92AW/ref=sr_1_1?ie=UTF8&qid=1252617701&sr=1-1
     

Share This Page