ARC上的UIPopover [英] UIPopover on ARC

查看:58
本文介绍了ARC上的UIPopover的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在具有以下代码的iPad应用程序上使用ARC,弹出窗口在屏幕上闪烁,但没有停留. 我做错了什么? 请帮助

I am using ARC on an iPad app with the code below, the popover flashes on the screen, but doesn't stay. What I am doing wrong? Please help

- (IBAction)photoLibraryAction:(id)sender

{   

   UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
   [imagePicker setDelegate:self];

   UIPopoverController *pop1 = [[UIPopoverController alloc]     initWithContentViewController:imagePicker];
    [pop1 setDelegate:self];
    [pop1 presentPopoverFromBarButtonItem:sender  permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    [pop1 setPopoverContentSize:CGSizeMake(320, 400)];
}


    if  ([pop1 isPopoverVisible])
    {
        // Popover is not visible
        [pop1 dismissPopoverAnimated:YES];

    }

}

推荐答案

在ARC中,pop1将在-photoLibraryAction:返回后立即释放,因为ARC不知道-presentPopoverFromBarButtonItem:permittedArrowDirections:使对象在其范围之外可用.
您必须为弹出式控制器添加一个实例变量,以便ARC不会释放它.您的if语句也是无效的,因为当该方法返回时,pop1不再可供您使用.您还必须在那里使用实例变量.

In ARC, pop1 will be released right after -photoLibraryAction: returns, because ARC doesn't know that -presentPopoverFromBarButtonItem:permittedArrowDirections: makes the object usable beyond its scope.
You'll have to add an instance variable for your popover controller so ARC doesn't release it. Your if-statement is invalid, too, because when the method returns, pop1 is no longer available for you to use. You'll have to use an instance variable there as well.

这篇关于ARC上的UIPopover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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