ポップオーバー コントローラーにボタンがあります。これを使用してポップオーバーを閉じたいので、表示中のビュー コントローラー (「ルート」ビュー コントローラー) のメソッド (dismissPopover) にアクセスしようとしています。
注:ポップオーバーを閉じる方法は、デリゲートであるルート VC で既に設定され、機能しています。私がそれを呼び出すと、ポップオーバーが消えます。ポップオーバーからメソッドにアクセスするだけです。
これを行うには、AppDelegate にプロパティを設定し、次のように rootVC のインスタンスを取得しますself.rootController = (ViewController*)self.window.rootViewController;
。次に、以下のように、ルート VC クラスと AppDelegate をポップオーバーのビュー コントローラーのクラスにインポートしました。rootVC とメソッドにアクセスできるようですが、結果はメソッドを起動しません。ここで何が欠けているのか分かりますか?
#import "ViewController.h"
#import "AppDelegate.h"
ボタンに接続されたアクション:
- (IBAction)dismissPopover:(id)sender {
//Checking the button works, it does:
NSLog(@"dismissPopover, from popover");
//Trying to get an instance of the rootViewController, the "presenting view controller"
ViewController *rootVC = [(AppDelegate *)[[UIApplication sharedApplication] delegate] rootController];
//trying to access the method in the rootVC that dismisses the popover
[rootVC dismissPopover];
//Tried the following code, does nothing:
//[self dismissPopoverAnimated:YES];
}
注:少し複雑になりすぎたため、ポップオーバーの使用を断念しました。ビュー コントローラーを UIView に読み込もうとしました (ペン先の内容をポップアップ ビューに読み込むことができました)。それも少し複雑になりました。そのため、今のところ、UIView で目的のインターフェイスをプログラムで構築しているだけです。これまでのところうまくいきます。