Skip to content

Instantly share code, notes, and snippets.

@eroth
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eroth/7e00fb1455e96ba7dbc3 to your computer and use it in GitHub Desktop.
Save eroth/7e00fb1455e96ba7dbc3 to your computer and use it in GitHub Desktop.
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];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment