UIViewController& UIview dealloc没有被调用 [英] UIViewController & UIview dealloc not getting called
问题描述
UIView栏有一个后退按钮,我使用Delegate方法(我已经声明了一个协议),当后台按钮被预先通知到视图控制器。
我在CustomNavigation中使用委托bar
id delegate;
在主控制器中,当我分配导航栏时,我设置代理
topBar = [[TopNavigationBar alloc] initWithFrame:CGRectMake(0,0,480,40)];
topBar.lblTitle.text = @Shop;
topBar.delegate = self;
我在ViewControllers dealloc中发布了这个栏。
现在,当我按后退按钮时,我使用delegate方法在主ViewController中调用popViewController。
// in自定义栏
- (void)ButtonPressed {
[delegate TopNavigationBarBackButtonPressed];
}
//在查看COntroller
- (void)TopNavigationBarBackButtonPressed {
[self.navigationController popViewControllerAnimated:YES];
}
现在ViewController被弹出,控件转到上一个viewController,但是dealloc在ViewController和UIView中都没有触发
我做错了什么?
OK!终于明白了问题是什么。
是的,是代表。所以在我的后退按钮方法中,我需要将代理设置为NIL。
- (void)TopNavigationBarBackButtonPressed {
topBar.delegate = nil;
[self.navigationController popViewControllerAnimated:YES];
}
而且,所有的dealloc被调用。你自定义协议我的生命的2天我永远不会回来。
编辑:
OK不需要将委托设置为nil。
我遇到了所有问题,因为在我保留代表的财产中。
code> @property(nonatomic,retain)id< ASNavigationDelegate> delegate;
这应该是
@property(assign)id< ASNavigationDelegate>代表;
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.
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.
I use delegate in my CustomNavigation Bar id delegate;
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;
I release this Bar in the ViewControllers dealloc.
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];
}
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
What am i doing wrong?
OK! Finally understood what the problem was.
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];
}
And voila, all the dealloc get called. Damn you custom Protocol. 2 Days of my life i will never get back.
EDIT: 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;
This should be
@property(assign)id <ASNavigationDelegate> delegate;
这篇关于UIViewController& UIview dealloc没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!