Hazel Sophie
Hazel Sophie

Reputation: 1385

uiviewcontroller in nib file

i was studying uiviewcontroller apple guide in which it says two approaches for uiviewcontroller one of the approach allow to store uiviewcontroller to store in nib file by dragging dropping viewcontroller object ... but i didn't understand that after dragging dropping it what to do next with it should i create new `UIVC class and refer to that object i dragged dropped in nib file??

we already do that normally create UIVC class and assign to nib file owner.

this is confusing me please help.

thanks in advance and please ignore any silly mistakes if u found in this question i am a newbie.

Upvotes: 1

Views: 1982

Answers (1)

rob mayoff
rob mayoff

Reputation: 385500

Here's an example of how you could put your view controller in the nib.

  1. Start with an empty nib (XIB).

  2. Select the File's Owner placeholder in your nib. In the Identity Inspector, set the class of File's Owner to your application delegate class (probably AppDelegate or something similar).

  3. Drag and drop a UIWindow into your nib. Connect the window outlet of File's Owner to this window object.

  4. Create your UIViewController subclass. Let's call it HazelViewController.

  5. Drag and drop a UIViewController into your nib file. In the Identity Inspector, set the custom class of this object to HazelViewController.

  6. Connect the rootViewController outlet of the window object to the HazelViewController object.

  7. Drag and drop a UIView onto the window object in your nib. Connect the view outlet of HazelViewController to this view.

  8. Drop other user interface objects onto this view. Connect them to outlets or actions of the HazelViewController object as necessary.

  9. In the application:didFinishLaunchingWithOptions: method of AppDelegate, load the nib, using the AppDelegate object as the file's owner:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options {
        [[NSBundle mainBundle] loadNibNamed:@"myNib" owner:self options:nil];
        [self.window makeKeyAndVisible];
        return YES;
    }
    

Upvotes: 3

Related Questions