我想玩 UIPopupController,我知道我无法检测到我的弹出框何时关闭。我的步骤:
1. 从 XCode 创建示例(文件 -> 新项目 -> 实用程序)
2. 添加到 MainViewController.hUIPopoverControllerDelegate
#import "FlipsideViewController.h"
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate,UIPopoverControllerDelegate>
@property (strong, nonatomic) UIPopoverController *flipsidePopoverController;
- (IBAction)showInfo:(id)sender;
@end
- 在 MainViewController 中:
- (IBAction)showInfo:(id)sender { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil]; controller.delegate = self; controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [自我presentModalViewController:控制器动画:YES]; } 别的 { 如果(!self.flipsidePopoverController){ FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil]; controller.delegate = self; self.flipsidePopoverController.delegate = self self.flipsidePopoverController = [[UIPopoverController alloc] initWithContentViewController:controller]; } if ([self.flipsidePopoverController isPopoverVisible]) { [self.flipsidePopoverControllerdismissPopoverAnimated:YES]; } 别的 { [self.flipsidePopoverController presentPopoverFromBarButtonItem:sender allowedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } } } -(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController { NSLog(@"OLOLO"); }
但是当我点击某个地方并且弹出框消失时,控制台中没有 NSLog 消息。我究竟做错了什么?