eroth
6/29/2014 - 9:38 PM

Pt 2: Obj-C find a parent UIViewController from the child VC (when the child's been pushed from a UINavigationController), then add a custom

Pt 2: Obj-C find a parent UIViewController from the child VC (when the child's been pushed from a UINavigationController), then add a custom button to the child that will trigger a method on the parent

// This can all be done from the parent VC--AddSearchRegionsViewController is child

AddSearchRegionsViewController *addSearchRegionsVC = [[AddSearchRegionsViewController alloc] initWithNibName:@"BaseTableView" bundle:[NSBundle mainBundle]];

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Test" style:UIBarButtonItemStyleBordered target:self action:@selector(didPressBackButtonOnAddSearchRegionsVC)];
addSearchRegionsVC.navigationItem.backBarButtonItem = backButton;
    
[self.navigationController pushViewController:addSearchRegionsVC animated:YES];

-(void)didPressBackButtonOnAddSearchRegionsVC {
    for (AddSearchRegionsViewController *child in self.navigationController.viewControllers)
        if ([child isKindOfClass:[AddSearchRegionsViewController class]]) {
            self.selectedCellsFromRegions = child.selectedCells;
        }
    [self.navigationController popToViewController:self animated:YES];
    
}