我正在使用带有ARC的XCode 4.5创建一个iPad版本的Master Detail Application。
我已经设置了iPadMaster.h / .m(作为我的主人)和iPadDetailViewController.h / m(作为我的细节)。

当用户单击/选择iPadMaster上的行时,我试图从iPadDetailViewController加载不同的视图控制器。

我在iPadMaster.m上将其设置为:

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


并在[viewDidLoad]上的iPadDetailViewController.m上尝试了这个愚蠢的特技:

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;
        }


在iPhone上,我只是在- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath上贴上“开关盒”,但我对iPad环境迷失了……

提前感谢...

最佳答案

拆分视图控制器具有一个属性viewControllers。索引为1的对象是详细信息控制器。您应该只创建一个可变的viewControllers副本,用新的控制器替换索引1处的对象,并将该数组设置为拆分视图的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;

10-07 22:19