PDA

View Full Version : How to specify a view .xib file




tommyh1122
May 20, 2010, 08:39 PM
I am hoping someone can help me. I am new to iPhone development and have a problem that is probably pretty simple.

If you have a .xib file with two views how do you specify a view to load? From the main screen I have two buttons one is to call one view the other to call the other view from the .xib file. When I make the call it is loading the view that is connected with the Files's Owner view.


- (IBAction)switchLFamilies:(id)sender
{
SecondSwapeViewController *familiesL = [[SecondSwapeViewController alloc] initWithNibName:nil bundle:nil];
familiesL.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:familiesL animated:YES];

}

Any help would be appreciated...Thank you..



PhoneyDeveloper
May 20, 2010, 10:12 PM
When your view controller is presented it obviously shows the view that is set as its view property. If you want to show another view then you need to have an outlet for the other view and then set the view controller's self.view to the other view.

tommyh1122
May 21, 2010, 04:44 AM
I do have an outlet for each of the view's (portrait, landscape) but this not being called from the SecondSwapeViewController.m, it is being called from SwapeViewController.m.

PhoneyDeveloper
May 21, 2010, 08:59 AM
Add a method to your view controller that has two views. This method will save a BOOL that tells it which view should be shown and set self.view = whateverView. Also add code that sets the correct view based on this BOOL in the view controller's viewDidLoad. After you alloc/init the view controller call this method.


SecondSwapeViewController *familiesL = [[SecondSwapeViewController alloc] initWithNibName:nil bundle:nil];
familiesL.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[familiesL showView2:YES];
[self presentModalViewController:familiesL animated:YES];