2

AppDelegate我们创建一个DetailView时,然后在它上面loginView呈现一个 ( UIModalPresentationFullScreen)。登录后,loginView被解雇。

DetailViewtableView当您选择一个单元格/行并detailView按下第二个时,有一个和。

到目前为止我做了什么:在AppDelegate我要求UI_USER_INTERFACE_IDIOM()以及何时iPad创建成语时splitView

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    FirstDetailViewController* fdvc = [[FirstDetailViewController alloc] initWithNibName:@"FirstDetailViewController" bundle:nil];
    SecondDetailViewController* sdvc = [[SecondDetailViewController alloc] initWithNibName:@"SecondDetailViewController" bundle:nil];

    UINavigationController* fdvcNavigationController = [[UINavigationController alloc] initWithRootViewController:fdvc];
    UINavigationController* sdvcNavigationController = [[UINavigationController alloc] initWithRootViewController:sdvc];

    splitViewController = [[UISplitViewController alloc] init];
    splitViewController.viewControllers = [NSArray arrayWithObjects:fdvcNavigationController, sdvcNavigationController, nil];

登录后,我的LoginView被关闭并显示我的UISplitViewController,第一个DetailView在左侧(主)。所以这里一切都很顺利。

现在我转到FirstDetailViewController.m并搜索didSelectRowAtIndexPath,因为我在“iPhone 版本”中找到了对SecondDetailViewController的 pushView。

这就是我卡住的地方。我已经尝试了几个SplitView教程并阅读了其他人关于splitview.

但我认为我的问题是某种“基本”问题,因为我通常是编程/iOS 新手,并不了解我所有的工具。

任何帮助,将不胜感激。

4

1 回答 1

3

在为表格中的项目编写带有表格视图和某种其他类型的“显示”视图的应用程序时,我这样做是为了使其在两种设备上都适用:

// In App Delegate...
-(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Create views
    MyTableViewController* myTable = [[MyTableViewController alloc] init];
    MyDetailViewController* myDetail = [[MyDetailViewController alloc] init];
    UINavigationController* tableNav = [[UINavigationController alloc] initWithRootViewController:myTable];
    UINavigationController* detailNav = [[UINavigationController alloc] initWithRootViewController:myDetail];

    // Check device type
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {

        // Use a split view
        UISplitViewController* splitView = [[UISplitViewController alloc] init];
        split.viewControllers = @[tableNav, detailNav];
        self.window.rootViewController = split;

    } else {

        // Use a single view for iPhone
        self.window.rootViewController = tableNav;

    }

}

.

// In table view
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Check device type
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {

        // Tell the already visible detail view to load something
        MyData* data = ...; \\ Get your thing to display however you want
        [[NSNotificationCenter defaultCenter] postNotificationName:@"DisplayMyData" object:data];

    } else {

        // No detail controller exists yet, so create it
        MyDetailViewController* myDetail = [[MyDetailViewController alloc] init];
        [self.navigationController pushViewController:myDetail animated:YES];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"DisplayMyData" object:data];

    }

}

.

// In detail view
-(void) viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displayData:) name:@"DisplayMyData" object:nil];

}

-(void) displayData:(NSNotification*)notify {

    MyData* data = (MyData*) notify.object;

    ... // Display however...

}
于 2013-04-02T13:10:52.183 回答