0

我正在使用带有 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;
}

并在 iPadDetailViewController.m 上尝试了这个愚蠢的特技[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;
        }

在 iPhone 上,我只会在- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPathiPad 环境中粘贴“开关盒”,但我迷失了......

提前谢谢...

4

1 回答 1

1

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;
于 2013-03-30T00:52:20.600 回答