I am using UISplitViewController for an application on an iPad. The first task was to show the main and detailed view in portrait mode. I did it like this:
// It is possible to keep the Master View in portrait mode // also. Just pass YES to this method to enable this mode. - (id) initWithMasterInPortraitMode:(BOOL) masterInPortrait { self = [super init]; self.keepMasterInPortraitMode = masterInPortrait; return self; } // Thanks to http://intensedebate.com/profiles/fgrios for this code snippet -(void) viewWillAppear:(BOOL)animated { NSLog(@"viewWillAppear"); if(keepMasterInPortraitMode == NO) { return; } //check interface orientation at first view and adjust it //if it is in portrait mode if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { UIViewController* master = [self.viewControllers objectAtIndex:0]; UIViewController* detail = [self.viewControllers objectAtIndex:1]; [self setupPortraitMode:master detail:detail]; } } // Thanks to http://intensedebate.com/profiles/fgrios for this code snippet - (void)setupPortraitMode:(UIViewController*)master detail:(UIViewController*)detail { //adjust master view CGRect f = master.view.frame; f.size.width = 320; f.size.height = 1024; f.origin.x = 0; f.origin.y = 0; [master.view setFrame:f]; //adjust detail view f = detail.view.frame; f.size.width = 448; f.size.height = 1024; f.origin.x = 321; f.origin.y = 0; [detail.view setFrame:f]; }
I create a splitView as follows:
MySplitViewController *mySplitViewController = [[MySplitViewController alloc] initWithMasterInPortraitMode:YES];
Well, this works fine, and when I launch the app in portrait mode, it shows both the main and detailed side-by-side views.
Everything is working now. But I want to show a different view in the detailView for each record (row) in the main view. My didSelectRowAtIndexPath method in masterView looks like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { FirstDetailViewController *firstDetailView = [[FirstDetailViewController alloc] initWithNibName:@"firstDetailView" bundle:nil]; UINavigationController *firstDetailNavigationController = [[UINavigationController alloc] initWithRootViewController:firstDetailView]; [firstDetailView release]; [self.splitViewController setViewControllers:[NSArray arrayWithObjects:self.navigationController, firstDetailNavigationController, nil]]; } else { SecondDetailViewController *secondDetailView = [[SecondDetailViewController alloc] initWithNibName:@"secondDetailView" bundle:nil]; UINavigationController *secondDetailNavigationController = [[UINavigationController alloc] initWithRootViewController:secondDetailView]; [secondDetailView release]; [self.splitViewController setViewControllers:[NSArray arrayWithObjects:self.navigationController, secondDetailNavigationController, nil]]; } }
After clicking (touching) in the first or second row (in masterView), splitView shows only detailView (full screen) without masterView.
How can I make splitView show when changing both views, the main and the detailed view ???
Thanks for your help!
source share