Reputation: 1385
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
Reputation: 385500
Here's an example of how you could put your view controller in the nib.
Start with an empty nib (XIB).
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).
Drag and drop a UIWindow
into your nib. Connect the window
outlet of File's Owner to this window object.
Create your UIViewController
subclass. Let's call it HazelViewController
.
Drag and drop a UIViewController
into your nib file. In the Identity Inspector, set the custom class of this object to HazelViewController
.
Connect the rootViewController
outlet of the window object to the HazelViewController
object.
Drag and drop a UIView
onto the window object in your nib. Connect the view
outlet of HazelViewController
to this view.
Drop other user interface objects onto this view. Connect them to outlets or actions of the HazelViewController
object as necessary.
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