UIPopover on ARC

杀马特。学长 韩版系。学妹 提交于 2020-01-16 03:58:07

问题


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];

    }

}

回答1:


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.



来源:https://stackoverflow.com/questions/8967420/uipopover-on-arc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!