segue加载viewcontroller但不显示它 [英] segue loading viewcontroller but not displaying it

查看:81
本文介绍了segue加载viewcontroller但不显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从iPad应用程序中的代码调用segue时,显示View Controller时出现问题.

I have a problem displaying a View Controller when calling a segue from code in an iPad app.

通过

标识符: viewDocumentSegue ,样式:模式,演示文稿:默认,过渡:默认

Identifier: viewDocumentSegue, Style: Modal, Presentation: Default, Transition: Default

然后我使用第一个视图控制器调用segue

I'm then calling the segue from the first view controller using

[self performSegueWithIdentifier:@"viewDocumentSegue" sender:nil];

,然后使用

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIViewController *destination = segue.destinationViewController;

    if ([destination respondsToSelector:@selector(setFileURL:)]) {
        [destination setValue:fileName forKey:@"fileURL"];
    }
}

第二个视图控制器确实已加载,就像控制台中显示的 viewDidLoad viewWillAppear viewDidAppear 中的NSLogs一样,但未显示任何内容.

The second view controller does get loaded, as the NSLogs I have in viewDidLoad viewWillAppear and viewDidAppear show in the console, but nothing gets displayed.

我在想第二个视图控制器的视图位于视图层次结构中的某个位置.但是,我如何将其推到顶部呢?

I'm thinking the second view controller's view is somewhere in the view hierachy. But how do I force it to the top?

修改

这是界面的屏幕截图(某些东西需要涂黑).我添加了一些注释来解释结构.希望它会有所帮助.

Here is a screenshot of the interface (some thing needed to be blacked out). I've added some notes explaining the structure. Hopefully it will help.

(我尚无法上传图片,因此这是一个链接) http://www.linfoots.com/Screenshot.jpg

(I can't upload images yet so here's a link) http://www.linfoots.com/Screenshot.jpg

有什么建议吗?

谢谢

理查德

推荐答案

您没有提供我所要求的其他信息,因此无法详细回答您的问题.我建议您做的是仅用两个视图控制器创建一个全新的项目.以同样的方式将它们连接到情节提要中.您将看到,您实际上想做的事情就可以了.一旦确信了这一点,就可以返回并查看遇到问题的项目的不同之处.

You're not providing the additional info I've asked for, so it's impossible to answer your question in detail. What I suggest you do is make a completely new project with just two view controllers. Connect them in the storyboard in the same way. You will see that what you're trying to do should in fact work just fine. Once you've convinced yourself of that, you can go back and see what the difference is in the project you're having trouble with.

好的,谢谢您的截屏.就像您在第二条评论中所猜到的那样,您似乎正在尝试将故事板与父视图控制器结合使用.这并非易事,因为情节提要不会让您的父视图控制器的孩子一无所知.使用多个情节提要,或者根本不使用情节提要,您会更加快乐.

Okay, thanks for the screen shot. It looks like you're trying to use a storyboard in connection with a parent view controller, exactly as I guessed in my second comment. That's not easy because a storyboard knows nothing of your parent view controller's children. You will be much happier using multiple storyboards, or no storyboard at all.

现在,我们来讨论使用父视图控制器的问题.您没有问这个问题,但这可能是您问题的核心.正确管理子视图控制器是至关重要的.请参阅我的书中的讨论:

Now we come to the problem of using a parent view controller. You didn't ask about this, but it could be at the heart of your issue. It is crucial that you manage child view controllers properly. See the discussion in my book:

http://www.apeth.com/iOSBook/ch19.html#_container_view_controllers

必须每次都进行这种精心制作的舞蹈,否则事情将无法正常进行:

You must do this elaborate dance every time, or things won't go right:

当视图控制器要成为您的父级视图控制器的孩子时:

When a view controller is to become your parent view controller’s child:

  • 您在父视图控制器上调用addChildViewController:.子级会自动添加到父级的childViewControllers数组中,并保留该数组.
  • 如果这是添加子视图控制器的意思,则可以将子视图控制器的视图添加到界面中.
  • 您将didMoveToParentViewController:发送给以父视图控制器作为其参数的孩子.

当视图控制器不再是您的父级视图控制器的孩子时:

When a view controller is to cease being your parent view controller’s child:

  • 您将使用nil参数将willMoveToParentViewController:发送给孩子.
  • 如果这是删除子视图控制器的意思,则从界面中删除子视图控制器的视图.
  • 您将removeFromParentViewController发送给孩子.将从子级的childViewControllers数组中自动删除该子级,然后释放该子级.

最后,当执行模态转换时,父链中的definesPresentationContext变得至关重要,因此模态视图知道在界面中要替换的视图.我的书中的这个可下载示例演示了必要的区别:

Finally, when you do a modal transition, definesPresentationContext in your parent chain becomes crucial so that the modal view knows what view to replace in the interface. This downloadable example from my book demonstrates the necessary distinctions:

https://github.com/mattneub/Programming-iOS-4-Book-Examples/tree/master/convertedToIOS5/p476containerController2

这篇关于segue加载viewcontroller但不显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆