Reputation: 673
IBAction does nothing. Logs "Back" to console so the connection's OK. self.topView also does nothing when the IBAction is called
-(IBAction)loadSettingsView:(id)sender;
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[[NSBundle mainBundle] loadNibNamed:@"settingsView_iphone" owner:self options:nil];
} else {
[[NSBundle mainBundle] loadNibNamed:@"settingsView_ipad" owner:self options:nil];
}
[self.view addSubview:topView];
}
-(IBAction)loadMainView:(id)sender;
{
[topView removeFromSuperview];
NSLog(@"back");
}
Upvotes: 0
Views: 80
Reputation: 673
Fund a much easier solution. Simply created a new view in the main view's nib and attached an IBOutlet to it. Works like a dream.
-(IBAction)loadSettingsView:(id)sender;
{
[self.view addSubview:settingsView];
}
-(IBAction)loadMainView:(id)sender;
{
[settingsView removeFromSuperview];
}
Upvotes: 0
Reputation: 1176
I hope I am not making too many assumptions here, but this should solve your problem. I am assuming topView
is a member of the current class:
-(IBAction)loadSettingsView:(id)sender;
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
topView = [[[NSBundle mainBundle] loadNibNamed:@"settingsView_iphone" owner:self options:nil] objectAtIndex:0];
} else {
topView = [[[NSBundle mainBundle] loadNibNamed:@"settingsView_ipad" owner:self options:nil] objectAtIndex:0];
}
[self.view addSubview:topView];
}
-(IBAction)loadMainView:(id)sender;
{
[topView removeFromSuperview];
NSLog(@"back");
}
Basically, the loadNibNamed
method you are using is returning an array with all the top-level views in the nib. If you want a reference to these views (And here I am assuming there is one view in the nib), you need to actually assign your topView
variable. Currently topView
is probably nil, so your removeFromSuperview
call is doing nothing.
Upvotes: 3