UIViewController & UIview dealloc does not receive a call

I have a navigation-based view controller, and in the view controller I hid the top navigation bar and used a custom UIView as the navigation bar.

There is a back button in the UIView panel, and I use the Delegate methods (I announced the protocol) to communicate with the view controller when the back button is saved.

I use a delegate in my panel CustomNavigation id of the delegate;

and in the main view controller, when I select 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 panel in the ViewControllers dealloc.

Now, when I click the back button, I use the delegate method to call the popViewController in the main ViewController.

 //in Custom Bar -(void)ButtonPressed { [delegate TopNavigationBarBackButtonPressed]; } //In View COntroller -(void)TopNavigationBarBackButtonPressed { [self.navigationController popViewControllerAnimated:YES]; } 

The ViewController now opens and the control goes back to the previous viewController, but dealloc does not start in both the ViewController and the UIView

What am I doing wrong?

+7
source share
1 answer

OK! Finally I realized what the problem was.

Yes, it was a delegate. Therefore, in my button click method, I need to set the delegate to NIL.

 -(void)TopNavigationBarBackButtonPressed { topBar.delegate = nil; [self.navigationController popViewControllerAnimated:YES]; } 

And voila, all dealloc get. Damn, user protocol. 2 days of my life I will never return.

EDIT: OK there is no need to set the delegate to zero.

I had all the problems because I kept the delegate in the property.

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

It should be

 @property(assign)id <ASNavigationDelegate> delegate; 
+16
source

All Articles