UIViewController& amp; UIview dealloc没有被调用 [英] UIViewController & UIview dealloc not getting called

查看:85
本文介绍了UIViewController& amp; UIview dealloc没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于导航的视图控制器,并且在视图控制器中,我隐藏了顶部导航栏,并使用自定义UIView作为导航栏.

I have a Navigation based view controller and in the view controller i have hidden the top navigation bar and use a custom UIView as the navigation bar.

UIView栏上有一个后退按钮,当按下后退按钮时,我使用Delegate方法(我已声明一个协议)与视图控制器进行通信.

The UIView bar has a back button and I use Delegate methods(I have declared a protocol) to communicate to the view controller when the back button is preesed.

我在CustomNavigation栏中使用委托 id代表;

I use delegate in my CustomNavigation Bar id delegate;

,并且在主View Controller中,当我分配导航栏时,我设置了委托

and In the main View Controller when i allocate the navigation bar i set the delegate

topBar = [[TopNavigationBar alloc] initWithFrame:CGRectMake(0, 0, 480, 40)];
topBar.lblTitle.text = @"Shop";
topBar.delegate = self;

我在ViewControllers的dealloc中释放此Bar.

I release this Bar in the ViewControllers dealloc.

现在,当我按下后退按钮时,我使用委托方法在主ViewController中调用popViewController.

Now when i press the back button I use delegate method to call a popViewController in the main ViewController.

//in Custom Bar
-(void)ButtonPressed {
    [delegate TopNavigationBarBackButtonPressed];   
}

//In View COntroller
-(void)TopNavigationBarBackButtonPressed {

    [self.navigationController popViewControllerAnimated:YES];
}

现在,将弹出ViewController并将控件移至上一个viewController,但不会同时在ViewController和UIView中触发dealloc

Now the ViewController is poped and the control goes to the previous viewController but the dealloc is not fired in both the ViewController and the UIView

我在做什么错了?

推荐答案

好!终于了解了问题所在.

OK! Finally understood what the problem was.

是的,是代表.因此,在我的按下后退按钮"方法中,我需要将委托设置为NIL.

Yes it was the delegate. So in my "back button pressed" method, I need to set the delegate to NIL.

-(void)TopNavigationBarBackButtonPressed {

 topBar.delegate = nil;
[self.navigationController popViewControllerAnimated:YES];
}

瞧,所有的dealloc都会被调用.该死的自定义协议.我一生的2天,我永远都不会回来.

And voila, all the dealloc get called. Damn you custom Protocol. 2 Days of my life i will never get back.

确定,无需将委托设置为nil.

OK no need to set the delegate to nil.

我遇到了所有问题,因为在财产中我保留了委托人.

I was having all the problems because in the property i was retaining the delegate.

@property(nonatomic, retain)id <ASNavigationDelegate>delegate;

应该是

@property(assign)id <ASNavigationDelegate> delegate;

这篇关于UIViewController&amp; amp; UIview dealloc没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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