segue loading viewcontroller but not displaying it

后端 未结 1 887
情话喂你
情话喂你 2020-12-22 06:28

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

I have the segue setup in IB by Ctrl dragging from one view controller t

相关标签:
1条回答
  • 2020-12-22 06:54

    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.

    EDIT:

    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:

    • You call addChildViewController: on your parent view controller. The child is automatically added to the parent’s childViewControllers array, which retains it.
    • You get the child view controller’s view into your interface, if that’s what adding a child view controller means.
    • You send didMoveToParentViewController: to the child with the parent view controller as its argument.

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

    • You send willMoveToParentViewController: to the child with a nil argument.
    • You remove the child view controller’s view from your interface, if that’s what removing a child view controller means.
    • You send removeFromParentViewController to the child. The child is automatically removed from the parent’s childViewControllers array, which releases it.

    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

    0 讨论(0)
提交回复
热议问题