私はこれがあなたが探しているものだと思います、
[self dismissViewControllerAnimated:YES completion:^{
[self.mainController aMethod];
}];
self
上記のコードでは、ブロックの外側で宣言し、次のように使用する必要があります。
__block SecondViewController *object = self;
[self dismissViewControllerAnimated:YES completion:^{
[object.mainController aMethod];
}];
self
ブロックに保持されないようにするためです。
アップデート:
今問題を手に入れました。mainController
の .h ファイルでプロパティとして宣言する必要がありますsecondViewController
。その後、secondViewController
fromを提示するときは、次の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];
}];