我需要在presentMoalViewController之後訪問parentViewController。 這是我的方法,我在firstViewController調用查看secondViewController:如何在presentModalViewController之後訪問parentViewController?
- (void)viewData {
SecondViewController *viewCtrl = [self.storyboard instantiateViewControllerWithIdentifier:@"select_data"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewCtrl];
navigationController.navigationBar.barStyle = UIBarStyleBlack;
UIBarButtonItem *saveButton = [[[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStyleDone target:viewCtrl action:@selector(saveData)] autorelease];
viewCtrl.navigationItem.rightBarButtonItem = salvaButton;
UIBarButtonItem *undoButton = [[[UIBarButtonItem alloc] initWithTitle:@"Undo" style:UIBarButtonItemStyleBordered target:viewCtrl action:@selector(backView)] autorelease];
viewCtrl.navigationItem.leftBarButtonItem = annullaButton;
[self presentModalViewController:navigationController animated:YES];
}
當我點擊saveButton,我嘗試進入parentViewController以這種方式,但它不工作:
- (void) saveData {
FirstViewController *parentView = (FirstViewController*)[[self navigationController] presentingViewController];
parentView.dataString = [[NSMutableString alloc] initWithFormat:@"new string"];
[parentView performSelectorInBackground:@selector(myMethod) withObject:nil];
[self dismissModalViewControllerAnimated:YES];
}
當myMethod調用你必須做的事情時,我沒有得到? – 2012-01-09 12:22:43
我必須重新加載我的tableView – Dany 2012-01-09 12:33:20