I currently have a popover that is a UITableViewController (called TableViewController) with 4 cells. Upon selecting one of the cells I would like to dismiss the popover and at the same time take a variable that is set based on the cell selection and use it as the text in a label outlet (i.e. self.styleText.text = thePopoverCellVariable;) in my other View Controller (called OtherViewController). How can I do this?
Right now this only works if I dismiss the popover by clicking outside. The code in the TableViewController.m is:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
((OtherViewController *)self.presentingViewController).thePopoverCellVariable=theVariable;
}
And in OtherViewController.m:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIStoryboardPopoverSegue *popoverSegue;
popoverSegue = (UIStoryboardPopoverSegue *)segue;
UIPopoverController *popoverController;
popoverController = popoverSegue.popoverController;
popoverController.delegate=self;
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
thePopoverCellVariable = ((StyleViewController *)popoverController.contentViewController).theVariable;
self.styleText.text=thePopoverCellVariable;
}
I finally figured this out. @Jeffery Thomas has 99% of the correct answer. The other 1% is that you have to dismiss the popover from the root view controller, in this case
OtherViewController. So I madepopoverControllera variable in the header file and implemented my code as followsAnd…