私はこれがあなたが探しているものだと思います、
[self dismissViewControllerAnimated:YES completion:^{
[self.mainController aMethod];
}];
self上記のコードでは、ブロックの外側で宣言し、次のように使用する必要があります。
__block SecondViewController *object = self;
[self dismissViewControllerAnimated:YES completion:^{
[object.mainController aMethod];
}];
selfブロックに保持されないようにするためです。
アップデート:
今問題を手に入れました。mainControllerの .h ファイルでプロパティとして宣言する必要がありますsecondViewController。その後、secondViewControllerfromを提示するときは、次のmaincontrollerように設定する必要があります。
secondViewController.maincontroller = self;
[self presentViewController:secondViewController animated:YES completion:Nil];
あなたのSecondViewController.hファイルでは、
@property(nonatomic, assign) MainController *mainController;
あなたのSecondViewController.mファイルでは、
@synthesis mainController;
更新 2:
maincontrollerプロパティとして宣言したくない場合は、これを試してください。これが正しい方法かどうかはわかりません。しかし、以前は機能していたようです。
MainController *mainController = (MainController *)[self.view.superview nextResponder];
[self dismissViewControllerAnimated:YES completion:^{
[mainController aMethod];
}];
更新 3 (推奨):
これはうまくいくはずです。チェックしてください。
MainController *mainController = (MainController *)self.parentViewController;
[self dismissViewControllerAnimated:YES completion:^{
[mainController aMethod];
}];