Container UIViewController Not Releasing it's Child View Controllers

前端 未结 3 1710
旧时难觅i
旧时难觅i 2021-01-31 22:02

I have a custom container UIViewController that has six child UIViewControllers, and a set of tabs that the user interacts with to switch between the child view controllers. The

3条回答
  •  名媛妹妹
    2021-01-31 22:02

    After hours and hours of trying to figure out what was going on I finally found what was causing my child view controllers from releasing correctly.

    Each view controller had the following notification declared in each so that they could respond to various events.

    [[NSNotificationCenter defaultCenter] addObserverForName:UPDATE_EVENT object:nil queue:nil usingBlock:^(NSNotification *note) {
        // do stuff when update happen
    }];
    

    Turns out for some reason that was keeping my view controllers from releasing correctly. I'm guessing that this added the view controller to the NSNotificationCenters observer list, and wasn't being removed when I did the following line.

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UPDATE_EVENT object:nil];
    

    So to fix my problem I just changed the notification to register like below.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateEvent:) name:UPDATE_EVENT object:nil];
    

    I have no idea why the way I was registering the notification wasn't allowing my view controller to release correctly, but this seemed to have fixed it. If anyone has any insight on why this issue would happen then please let me know.

    Thanks!

提交回复
热议问题