Apple の HIG は、ポップオーバー内に明示的な閉じるボタンがあってはならないと言いますが、求めていることを行うには 2 つのオプションがあります。
1) NSNotification を投稿する
また
2) ポップオーバー インスタンスが表示されるまで、ビュー階層をドリルダウンします。
1) ポップオーバーを表示しているビューの viewDidLoad メソッドで:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissThePopover) name:@"popoverShouldDismiss" object:nil];
「dismissThePopover」というメソッドを作成し、dealloc メソッドで removeObserver
-(void)dismissThePopover {
[self.popoverController dismissPopoverAnimated:YES];
}
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
popoverController の「閉じる」ボタンに、次の行を入力します。
[[NSNotificationCenter defaultCenter] postNotificationName:@"popoverShouldDismiss" object:nil];
これを行うと、アプリに通知が送信されます。他のビュー コントローラーがそれをリッスンするように登録しているため、その通知が表示されるたびに、指定したセレクター (この場合は、dismissThePopover) が呼び出されます。
2) ビュー階層をドリルダウンして、self.popoverController を見つけます。
これをチェックしてください。あなたのものは確かに異なりますが、全体的な考え方は同じです。AppDelegate から始めて、最初のビューコントローラーに移動し、self.popoverController オブジェクトに到達するまでサブビューに移動します。
MyAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
//appDelegate instance, in this case it's the .m file for your ApplicationDelegate
UISplitViewController *svc = appDelegate.splitViewController;
//In this case the first view inside the appDelegate is a SplitView, svc
UINavigationController *navc = [[svc viewControllers]objectAtIndex:0];
//a navigationController is at index:0 in the SplitView hierarchy. DetailView is at index:1
NSArray *vcs = [navc viewControllers];
//vcs is the array of different viewcontrollers inside the Navigation stack for nvc
iPadRootViewController *rootView = [vcs objectAtIndex:0];
//declare the rootView, which is the .m file that is at index:0 of the view array
UIPopoverController *pc = [rootView popoverController];
//HERE WE GO!!! popoverController is a property of iPadRootViewController's instance rootView, hereby referred to as pc.
[pc dismissPopoverAnimated:YES];
//bye bye, popoverController!
お役に立てれば