首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UISplitViewController - detailView没有显示

UISplitViewController - detailView没有显示
EN

Stack Overflow用户
提问于 2013-04-02 09:42:11
回答 1查看 1.4K关注 0票数 2

AppDelegate中,我们创建一个DetailView,然后在其之上显示一个loginView (UIModalPresentationFullScreen)。登录后,loginView将被解职。

DetailView有一个tableView,当您选择一个单元格/行并推送第二个detailView时。

到目前为止,我所做的是:在AppDelegate中我要求UI_USER_INTERFACE_IDIOM(),当成语是iPad时,我创建了一个splitView

代码语言:javascript
复制
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被取消,我的LoginView将显示出来,左边是第一个DetailView (主人)。所以这里一切都很好。

现在我去FirstDetailViewController.m并搜索didSelectRowAtIndexPath,因为在那里我在"iPhone版本“中找到了pushView to SecondDetailViewController

这就是我被困的地方。我已经尝试过几个SplitView教程,并阅读了其他有关splitview的问题。

但是我认为我的问题是某种“基本的”,因为我对编程/ iOS一般都是新手,而且不知道我的所有工具。

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-02 13:10:52

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

代码语言:javascript
复制
// 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;

    }

}

代码语言:javascript
复制
// 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];

    }

}

代码语言:javascript
复制
// 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...

}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15760872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档