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

问题描述

我向你保证,我确实为我的问题寻找答案,但没有一个是有帮助的。这里我有一个简单的代码,应该在 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仍然可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 01:48