5

これが私のアプリのデザインです。私はmainControllerどのプレゼントを持っていますかsecondViewController。ここで、メソッドを閉じてから、次のようsecondViewControllerに呼び出したいと思います。aMethodmainController

[self dismissViewControllerAnimated:YES completion:aMethod];

しかし、これは私にエラーを与えますuse of undeclared identifier 'aMethod'

明らかに、完了ハンドラを正しく使用していませんが、正しい方法がわかりません。

4

3 に答える 3

13

私はこれがあなたが探しているものだと思います、

[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];
                }];
于 2012-10-26T00:15:47.770 に答える
1

次のようなものが必要です。

[self dismissViewControllerAnimated:YES completion:^{
            ...
            <do something on completion here>
            ...
        }];
于 2012-10-26T00:09:35.083 に答える
-3

これを宣言します:dismissViewControllerAnimated:YES completion:Nil

お役に立てば幸いです。

于 2012-10-26T00:07:25.737 に答える