Follow the following steps
UIView
.MyView.xib
.UIViewController
from NSObject
in xib. See the image below
Connect the File Owner View to your View. See the image below
Change the class of your View to MyView
. Same as 3.
Here is the code to load the View:
UIViewController *controller=[[UIViewController alloc] initWithNibName:@"MyView" bundle:nil];
MyView* view=(MyView*)controller.view;
[self.view addSubview:myview];
Hope it helps.
Clarification:
UIViewController
is used to load your xib and the View which the UIViewController
has is actually MyView
which you have assigned in the MyView xib..
Demo I have made a demo grab here