i try to add a UIView to my application. it does work but not as expected. i´ve defined the socialActionView in my header and made a @synthesize in my view controller.
the nib-file is loaded when the user tabs a button. i thought i have to call the addSubview-method to show the view. but it shows up even i i don´t do it.
if i call the addSubView-method anyway the app crashes when i load the view with the message “warning: Unable to restore previously selected frame.”
can anybody explain what´s goning on here? i don´t understand that.
- (IBAction)didTapOkSocialAction:(id)sender;
{
self.socialActionView = [[[NSBundle mainBundle] loadNibNamed:@"SocialActionViewController" owner:self options:nil] objectAtIndex:0];
//[self.view addSubview:socialActionView];
}
EDIT
in this case the solution was to set the file´s owner of my SocialActionViewController.xib to ViewController.h. i don´t know yet how to add a UIView from NIB attached to another view controller class than the view controller where the view is loaded into.
Your
socialActionViewis already bound to the view placeholder in its superview.So: its already there (its reference is already added as a subview) but it is
niluntil you actually load it.EDIT: it’s not clear how you have everything connected there, but from your added info below i’ll take a wild guess.
Try this code:
EDIT: since you want to programatically load a viewcontroller from .xib you can do it like so (supposably viewcontroller is defined in MyViewController.h,.m,.xib):
then you can add it’s view: