WEPopoverController 显示视图并在第二秒后关闭它

WEPopoverController show view and after second closed it

我尝试使用弹出窗口显示视图。由于 UIPopoverController 在 IPhone 上不起作用,我使用 WEPopoverController。

我的代码:

UIViewController *controller = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"GetDateController"];
controller.modalPresentationStyle = UIModalPresentationPopover;
WEPopoverController *pop = [[WEPopoverController alloc] initWithContentViewController:controller];
pop.delegate = self;
CGRect screen = [[UIScreen mainScreen]bounds];
CGRect r = CGRectMake(8, 8, screen.size.width-8, 57);
pop.popoverContentSize = r.size;
[pop presentPopoverFromRect:CGRectMake(200, 100, 0, 0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

当我启动程序时,我看到 window 上有一个弹出窗口,它立即消失了。 当我在 IPhone 上使用 UIPopoverController 程序崩溃时,在 iPad 上一切正常。

我需要对 WEPopoverController 做什么才能让它工作?

亚历山大。

那是因为view controller不拥有你创建的popover,没有强引用,ARC发现popover的引用计数为0,立即释放。您需要做的就是在创建后将弹出窗口设为视图控制器的属性。