UIPopoverController,UIActionSheet和模态视图控制器的保留/释放模式? [英] Retain/release pattern for UIPopoverController, UIActionSheet, and modal view controllers?

查看:131
本文介绍了UIPopoverController,UIActionSheet和模态视图控制器的保留/释放模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下实例所需的对象所有权模式有些不清楚。当我的UIViewController将弹出控制器,操作表或其他视图控制器显示为模态时,我是否需要挂起对该子控制器的保留引用,直到它被解除为止?

I'm somewhat unclear on the object ownership patterns required for the following instances. When my UIViewController presents a popover controller, an action sheet, or another view controller as modal, am I required to hang onto a retained reference to that child controller until it's been dismissed?

换句话说,下面的代码行是否有效地转移所有权,或者没有?

In other words, do the following lines of code effectively "transfer" ownership, or not?

[aPopoverController presentPopoverFromBarButtonItem:someButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];

[anActionSheet showFromBarButtonItem:someButtonItem animated:NO];

[aViewController presentModalViewController:someOtherViewController animated:YES];

有人能指出我有关此主题的明确文件吗?

Can someone point me to explicit documentation on this subject?

推荐答案

UIPopoverViewController有一个略微不同的内存管理/拥有。提出一个popover不会保留内存,所以你不能将你的popviewcontroller的所有权转移到呈现对象。

UIPopoverViewController has a slight different memory management/owning. Present a popover does not retain the memory, so you can't transfer the ownership of your popviewcontroller to the presenting object.

为了避免内存泄漏,你必须采用UIPopoverControllerDelegate并实现DidDismissPopOver方法如下:

To avoid memory leak, you have to adopt the UIPopoverControllerDelegate and implement the DidDismissPopOver method as follow:

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
    [popoverController release];
}

这样,您可以安全地分配并呈现PopOver:

This way, you can safe alloc and present a PopOver:

-(void)showSearch:(id)sender {
    SearchViewController *searchVC = [[SearchViewController alloc] init];
    UIPopoverController *popVC = [[UIPopoverController alloc] initWithContentViewController:searchVC];
    popVC.delegate = self;
    [popVC setPopoverContentSize:CGSizeMake(320, 100)];
    [popVC presentPopoverFromRect:CGRectMake(200, 200, 320, 100) inView:self.view permittedArrowDirections:0 animated:YES];
    [searchVC release];
}

这篇关于UIPopoverController,UIActionSheet和模态视图控制器的保留/释放模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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