How to pass parameters to a popover view controller inside a navigation controller

后端 未结 2 1072
清酒与你
清酒与你 2021-01-13 16:48

I have an iPad app with splitview and a right bar button in the navigation bar of the detailviewcontroller.

This button calls a popover constituted of a navigation c

相关标签:
2条回答
  • 2021-01-13 17:05

    I'm not entirely sure I follow, because the storyboard is a bit small for me to read. But you seem in your code to have created a sparkling new popoverFirstTVC and then thrown it away by the assignment

    popoverFirstTVC = segue.destinationViewController;
    

    If you comment that line out, then at then end write

    segue.destinationViewController.itsPopover = popoverFirstTVC;
    

    then you can pass off your fully-constructed and initialised popoverFirstTVC and have code in the second VC pick it up and run with it. Of course, you need

    @property (strong, readwrite) MyPopoverFirstTableViewController * itsPopover;
    

    in the header for your second VC.

    0 讨论(0)
  • 2021-01-13 17:21

    All the credit belongs to @Michael Kernahan, but as long as he don't post it as an answer I'll write it as a follow up for people looking for the same answer.

    In my case the problem was that I am assigning the destination controller which is the navigation controller

    popoverFirstTVC = segue.destinationViewController; 
    

    what I should do is to access the topViewController of that navigation controller.

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if([[segue identifier] isEqualToString:@"popoverButtonSegue"]){
            MyPopoverFirstTableViewController *popoverFirstTVC = (MyPopoverFirstTableViewController *)((UINavigationController *) segue.destinationViewController).topViewController;
    
            popoverFirstTVC.property1 = aProperty1;
            popoverFirstTVC.property2 = aProperty2;
    }
    
    0 讨论(0)
提交回复
热议问题