UIPopovercontroller dealloc 在 popover 仍然可见时达到 [英] UIPopovercontroller dealloc reached while popover is still visible

查看:32
本文介绍了UIPopovercontroller dealloc 在 popover 仍然可见时达到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我向您保证,我确实在 SO 中为我的问题寻找了答案,但没有一个有帮助.在这里,我得到了一个简单的代码,它应该在 UIPopoverController 中显示一个 UIImagePickerController:

I assure you that I did look for an answer in SO for my question but none of them were helpful. Here I got a simple code that should present a UIImagePickerController within a UIPopoverController:

-(void)takePicture:(id)sender{
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing=YES;
UIPopoverController *poc=[[UIPopoverController alloc] 
                            initWithContentViewController:picker];
[poc presentPopoverFromBarButtonItem:bbItem 
            permittedArrowDirections:UIPopoverArrowDirectionAny
                            animated:NO];
}

现在,即使从我第一次获得 [UIPopoveController dealloc] 达到同时...错误和程序崩溃.我没有按照 ARC 进行任何保留、发布或自动发布.从 ARC 中受益时,UIPopoverControllers 有什么特别的考虑吗?

Now, even from the first time I get [UIPopoveController dealloc] reached while... error and the program crashes. I'm not doing any retain,relase or autoreleases as per ARC. Is there any special consideration with UIPopoverControllers when benefitting from ARC?

推荐答案

UIPopoverControllers 应该始终保存在一个实例变量中.为它创建一个强大的属性是一个很好的做法.

UIPopoverControllers should always be held in an instance variable. It is a good practice to create a strong property for it.

更新:

从 iOS 8 开始,您应该使用 UIPopoverPresentationController.那么你就不需要保留对 popover 的引用,因为它是由呈现控制器管理的.

As of iOS 8 you should be using UIPopoverPresentationController. Then you don't need to keep a reference to the popover because it is managed by the presentation controller.

代码示例(适用于 iPhone 和 iPad):

Code example (works both on iPhone and iPad):

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = YES;
picker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController* popoverPC = picker.popoverPresentationController;
popoverPC.barButtonItem = bbItem;
popoverPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self presentViewController:picker animated:YES completion:nil];

这篇关于UIPopovercontroller dealloc 在 popover 仍然可见时达到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆