Joe Shamuraq
Joe Shamuraq

Reputation: 1385

Master Detail Application for iPad

I am creating an iPad version of Master Detail Application using XCode 4.5 with ARC. I have my iPadMaster.h/.m(as my master) and iPadDetailViewController.h/m(as my detail) set up.

I am trying to load different view controllers from iPadDetailViewController when users click/select the rows on iPadMaster.

I set this on iPadMaster.m at:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    iPadDetailViewController * DVC = [[iPadDetailViewController alloc]initWithNibName:nil bundle:nil];
    DVC.itemNumber = indexPath.row;
}

and tried this stupid stunt on iPadDetailViewController.m on [viewDidLoad]:

switch(_itemNumber)
    {

        case 0:
        {
            //Detail row
            vc1 *viewController = [[vc1 alloc] init];
            [self presentViewController:viewController animated:YES completion:nil];
            break;
        }
        case 1:
        {
            //Report row
            vc2 *viewController = [[vc2 alloc] init];
            //viewController.somePassedInData = theDataToPass;
            [self presentViewController:viewController animated:YES completion:nil];
            break;
        }
        case 2:
        {
            //Report row
            vc3 *viewController = [[vc3 alloc] init];
            //viewController.somePassedInData = theDataToPass;
            [self presentViewController:viewController animated:YES completion:nil];
            break;
        }

        ...
        case 9:
        {
            //Report row
            vc9 *viewController = [[vc9 alloc] init];
            //viewController.somePassedInData = theDataToPass;
            [self presentViewController:viewController animated:YES completion:nil];
            break;
        }
        default:
        {
            break;
        }

On iPhone i would just plaster the 'switch cases' in the - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath but i'm at lost with iPad environment...

Thanx in advance...

Upvotes: 0

Views: 279

Answers (1)

rdelmar
rdelmar

Reputation: 104092

The split view controller has a property, viewControllers. The object at index 1 is the detail controller. You should just create a mutable copy of viewControllers, replace the object at index 1 with your new controller, and set that array to be the split view's arrayControllers.

NextController *next = [[NextController alloc] init..... // or however you get your new controller
NSMutableArray *mut = [self.splitViewController.viewControllers mutableCopy];
[mut replaceObjectAtIndex:1 withObject:next];
self.splitViewController.viewControllers = mut;

Upvotes: 1

Related Questions