Reputation: 944
I just want to reduce the height of the NavigaitonBar.
I put the following code in ViewDidLoad then I ran the project. The height changed in a moment, but it was restored to the default height shortly .
CGRect navRect = self.navigationController.navigationBar.frame;
navRect.size.height = 30;
self.navigationController.navigationBar.frame = navRect;
And I tried to put these code in viewWillAppear, the same issue happened again!
But in viewDidAppear, it works properly, the height was changed.
I always add some barButtonItem in viewDidLoad. It illustrates that the NavigationController has been successfully initialized in viewDidLoad,but why can't the height be changed?
This confused me for a long time.
Thanks!
Upvotes: 1
Views: 262
Reputation:
if your table needs to load data every time with new Data then it should be under viewWillAppear Otherwise, if the table needs to be reload by a single Data which doesn't vary or there is not any editing operation performed on Data , you should use viewDidload
Upvotes: 1
Reputation: 411
Since Auto Layout was added the lifecycle of views also was changed.
All geometric modifications of subviews in view should be done in viewDidLayoutSubviews
method.
As you can see from the name of this method it means that all subviews will have placed properly at the moment when this method will be called.
Upvotes: 3