Cannot pass messages between main view controller and popover view

Tag: uitableview , uinavigationcontroller , uipopovercontroller , popover , uipopover Author: anhuaibao Date: 2011-04-19

I'm seem unable to get any kind of communication going between my Main View Controller and a Table View Controller which is being displayed inside a Popover View (iPad).

I'm setting up the Table View inside a Navigation Controller in the usual way:

// create popover
    if (self.popoverController == nil) {

    filesViewController = [[[MyTableViewController alloc] initWithFiles:fileList] autorelease];

    UINavigationController *navCtrl = [[[UINavigationController alloc] initWithRootViewController:filesViewController] autorelease];

    self.popoverController = [[UIPopoverController alloc] initWithContentViewController:navCtrl];

        self.popoverController.delegate = self;

        // resize popover
        self.popoverController.popoverContentSize = CGSizeMake(320.0, 44 + [fileList count] * 44);

Everything is working fine, and I'm passing an array of file names (fileList) into the Table View, which is held in the Table View as an array called listOfFiles. The Table View displays the filenames, and when one is selected by the user I want to pass that filename back to the Main View Controller. However, I cannot get any communication going back from the Table View's didSelectRowAtIndexPath method to the Main VC. I've tried all sorts of outlets going in various directions, and I've tried creating a new object in didSelectRowAtIndexPath to handle the filename coming from the Table View. I can pass the filename out to the new object, but when I try to send that into the Main VC it is null again. Everything I send to my Main VC while that popover is active comes up as null.

    - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {

    NSLog(@"%@", handler.addressForImageFile);

    self.popoverController = nil;
    [self.popoverController release];

Is there some reason why my Main VC won't get anything but null objects from my Table View? I've spent days trying so many different things. I feel like there's some fundamental gap in my knowledge of how popovers work. Surely there is a simple way to send a string back to my Main VC when it is selected from the Table View?

Thanks so much for any help!

Best Answer

There's propably a much better way to do this, but depending on the goal of passing the string, one way could be to use NSUserDefaults.


Thanks. I eventually solved this by using my Main View Controller as the data source and delegate for the Table View. Wish I had thought of that a few days ago and saved my self a whole lot of anguish!
It's worth noting that if you end up using the Main View Controller as a data source/delegate, this answer could save you some Googling -