views:

418

answers:

1

Hello,

I'm using UISplitViewController for app on iPad. The first task was to show master and detail view in portrait mode. I have done this like that:

// 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 splitView like this:

MySplitViewController *mySplitViewController = [[MySplitViewController alloc] initWithMasterInPortraitMode:YES];

Ok, that works ok and when I launch app in portrait mode it shows both master and detail view side by side.

Everything works for now. But I want to show a different view in detailView for each record (row) in master view. My didSelectRowAtIndexPath method in masterView looks like that:

- (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 a click (touch) on first or second row (in masterView) splitView shows only detailView (whole screen) with no masterView.

How can I force splitView to show on change both views, master and detail view ???

Thanks for your help!

A: 

I have found the solution. In masterView I created splitViewController instance and assign local instance to that instance:

settingsSplitViewController = (SettingsSplitViewController *)self.splitViewController;

In method didSelectRowAtIndexPath I did this like that:

[settingsSplitViewController setupPortraitMode:self.navigationController detail:detailNavigationController];

Hope it will help someone else to solve this kind of problem.

borut-t