Shubham Chawla
Shubham Chawla

Reputation: 132

Creating UIView in xib, interface builder and without using UIViewController to attach it to the window

I'm new to views and view controllers.....i was wondering if there is a way to create a view(UIView) using xib (i.e, I have all three files .m, .h and .xib of the UIView) and I attach it to the window like [window addSubview:myView];??

all the examples I have seen till now have used UIViewController to load the view using xib.

Upvotes: 0

Views: 195

Answers (1)

nsinvocation
nsinvocation

Reputation: 7637

Not sure why you want to do this, but here is what you can do: In -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions from AppDelegate class, load your custom view

CustomView *view = [[[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:nil options:nil] objectAtIndex:0];

Then add view to the window

[self.window addSubview:view];

That's it.

Upvotes: 1

Related Questions