适用于iPad的Master Detail应用程序

时间:2013-03-30 00:26:43

标签: ios objective-c xcode ios5 xcode4.5

我正在使用带有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环境中迷失了......

提前完成了......

1 个答案:

答案 0 :(得分:1)

拆分视图控制器有一个属性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;