سؤال

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 controller and two table views. as shown in the following picture

enter image description here

As the storyboard is small on the picture I add some explanation. The White controller is the detailViewController (right hand side of the splitviewcontroller), which is inside a navigtion controller. The three views on the right side of the white view are from left to right : navigationController, firstTableView, secondTableView.

My problem is that I need to pass parameters to the first table view to configure it correctly.

I use to do it like that when view controller were sharing the same navigation controller.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"popoverButtonSegue"]){
        MyPopoverFirstTableViewController *popoverFirstTVC = [[MyPopoverFirstTableViewController alloc] init];

        popoverFirstTVC = segue.destinationViewController;
        popoverFirstTVC.property1 = aProperty1;
        popoverFirstTVC.property2 = aProperty2;
    }
}

My Problem is that I get an error doing this because the destination controller is not my popoverFirstTableViewController but the NavigationController and the navigation controller of course does not haver "property1" and "property2".

Perhaps it's a basic question but I am stuck here.

How do I do to configure my tableview by assigning some of its properties I have defined when this table is inside a navigation controller ?

هل كانت مفيدة؟

المحلول

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;
}

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top