UIViewController和UIview dealloc没有被调用

B K*_*B K 7 delegates uiviewcontroller uiview dealloc ios4

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

UIView栏有一个后退按钮,我使用Delegate方法(我已经声明了一个协议)在后退按钮被预设时与视图控制器通信.

我在CustomNavigation Bar id委托中使用委托;

并在主视图控制器中,当我分配导航栏时,我设置了委托

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

我在ViewControllers dealloc中发布了这个Bar.

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

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

//In View COntroller
-(void)TopNavigationBarBackButtonPressed {

    [self.navigationController popViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)

现在ViewController是poped并且控件转到上一个viewController但是在ViewController和UIView中都没有触发dealloc

我究竟做错了什么?

B K*_*B K 17

好!终于明白了问题所在.

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

-(void)TopNavigationBarBackButtonPressed {

 topBar.delegate = nil;
[self.navigationController popViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)

瞧,所有dealloc都被称为.该死的你自定义协议.我生命中的2天永远不会回来.

编辑:确定无需将委托设置为nil.

我遇到了所有问题,因为我在保留代表的财产.

@property(nonatomic, retain)id <ASNavigationDelegate>delegate;
Run Code Online (Sandbox Code Playgroud)

这应该是

@property(assign)id <ASNavigationDelegate> delegate;
Run Code Online (Sandbox Code Playgroud)