English 中文(简体)
使用UINavigationController作为模式看待,在被解雇后不会释放这种观点。
原标题:Use UINavigationController as modal view, and view are not released after dismiss

I am using a class inherited from UINavigationController present as a modal view, in the navigation bar I have a button Done which will dismiss the modal view when user tap on it. Everything behave normal except the dealloc() in ImagePickerController, GroupPickerController (which is initialized as root view) not get called when I dismiss the modal view. This cause the leak of the memory.

Here is the code use it:

ImagePickerController *picker = [[ImagePickerController alloc] initWithRootViewController:nil];

// don t show animation since this may cause the screen flash with white background. 
[self presentModalViewController:picker animated:NO];

picker.navigationBar.barStyle = UIBarStyleBlack;
[picker release];

这里是图象PickerController, 它是UINavigation 主计长:

 - (id)initWithRootViewController:(UIViewController *)root {

    GroupPickerController *controller = [[GroupPickerController alloc] initWithNibName:nil bundle:nil];
    self = [super initWithRootViewController:controller];
    [controller release];
    if (self) {
        self.modalPresentationStyle = UIModalPresentationPageSheet;
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
}

-(void) dismiss
{
    [self.navigationController setViewControllers:nil];
    [self dismissModalViewControllerAnimated:YES];
}

这里是班轮冷却机的代码,是对航道的ton子的反应,以否定运输方式的观点:

...
#pragma mark - button actions
- (void)done {
    [self.parent dismiss];
}

I tried to manually remove the views from NavigationController, seemed not no effect at all... [self.navigationController setViewControllers:nil];

得到帮助!


<>执行>:

Please disregard this question, apparently it s a mistake. :(

最后,这个问题已经解决......不会改变任何法典,而是重建项目。

问题回答

First of all, you should not be subclassing UINavigationController:

这一类别并非用于分类。

这一行文是什么?

controller.parent = self;

如果控制者保留父母亲财产,你就会有一个保留周期,引起你所描述的问题。 认为UINavigationController中的所有观点控制员都能够利用天候机控制器的财产进入导航控制员。

There s is a difference between a UIViewController begin dismissed and released. When you dismiss it, it can be released at any moment, but not necessarily immediately.

Are you sure you have a memory leak ? Maybe the picker is released a few seconds after the dimiss.

如果你真的有记忆泄露,那就意味着还有另一个地方可以保留。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签