Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewWillDisappear nil values for navigation/tab controller

Tags:

ios

swift

I need to reconfigure the size of the UINavigationController inside my UITabController. This works fine when the view loads, in viewWillAppear(). However, when I try to resize in viewWillDisappear, I get nil values for both the Nav/Tab controller. Example:

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    self.navigationController?.hidesBarsOnSwipe = false //po self.navigationController --> nil
    ...
    var smallerFrame: CGRect = (self.tabBarController?.view.frame)!; //po self.tabBarController --> nil
    ...
}

I'm not sure what's going on. Why would this happen in viewWillDisappear but not viewWillAppear?

like image 739
goodcow Avatar asked Sep 24 '15 20:09

goodcow


1 Answers

I had the same problem. Ended up setting a weak property to navigation controller in viewDidLoad.

@property(weak, nonatomic) UINavigationController *weakNavigationController;
like image 105
almas Avatar answered Nov 15 '22 18:11

almas