我有这段代码
-(void)didPressButton:(int)tag
{
// Preventivi?
if (tag == 0)
{
if (addPrev == nil)
addPrev = [[avvAddPreventivoViewController alloc] init];
addPrev.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addPrev];
navigationController.navigationBarHidden = NO;
[[navigationController navigationBar] setBarStyle:UIBarStyleBlack];
[self presentViewController:navigationController animated:YES completion:nil];
addPrev = nil;
}
}
当我显示addPrev
内存增加时,显示内存时不释放。
当addPrev
解雇时会触发协议方法,didCancel
。我拦截它并释放addPrev
:
-(void)didCancel
{
[self dismissViewControllerAnimated:YES completion:nil];
addPrev = nil;
}
答案 0 :(得分:1)
Niling还导航控制器大大改善了内存分配。 另外,请小心释放可以在推送控制器的dealloc中释放的内容。
-(void)didPressButton:(int)tag
{
// Preventivi?
if (tag == 0)
{
if (addPrev == nil)
addPrev = [[avvAddPreventivoViewController alloc] init];
addPrev.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addPrev];
navigationController.navigationBarHidden = NO;
[[navigationController navigationBar] setBarStyle:UIBarStyleBlack];
[self presentViewController:navigationController animated:YES completion:nil];
addPrev = nil;
navigationController = nil;
}
}