I have two view controllers. I display the 1st one and then when I modally display the second one viewDidAppear gets called from the View Controller 1 after viewDidAppear gets executed from View Controller 2.
Why is View Controller 1's viewDidAppear getting called while in View Controller 2? Is this normal behavior?
More importantly the content view of a scrollview is getting resized when the viewDidAppear gets from the View Controller 1 gets called inside View Controller 2.
Related
I created two view controllers like
Navigation controller -> View Controller -> Details View Controller
1 2 3
The (2) View Controller has a button in it which when clicked will shows (3) Details View Controller. I have created a segue from button to (3) VC.
I have added deinit blocks in those two classes.
deinit {
print("vc deinit")
}
However, this does not get logged. When will a view controller get deallocated?
Sample code
In this case, the only deinit will get called is the second one (the one implemented in the Details View Controller) each time you tap the back button on the navigation (pop to the previous view controller).
So, why the first deinit (the one in the View Controller) didn't get called?
That's because it is the first view controller in the navigation controller stack. Pushing to the second view controller does not mean that the previous one(s) one has been deallocated and still exists as the first element in the navigation stack; As an example, that's why viewDidLoad method should not get called when you come back from a popped view controller, which means it did not get deallocated.
I am new to ios and working on container view first time.I have a containerview in a Taskviewcontroller .The containerview contains four childs i.e. Viewcontroller A,Viewcontroller B,Viewcontroller C,Viewcontroller D.
These Viewcontrollers contains table view cells .When I click on the cells of ViewcontrollerA it opens AdetailViewcontroller,When I click on the cells of ViewcontrollerB it opens BdetailViewcontroller,When I click on the cells of ViewcontrollerC it opens CdetailViewcontroller,When I click on the cells of ViewcontrollerD it opens DdetailViewcontroller.
These View controllers have back
(Task) button (that comes by default due to navigation).This button is suppose to take to the previous Viewcontroller,like if it is on CdetailViewcontroller,then it should bring back to CViewcontroller).But this doesn't happen actually .In every case ,it brings back to ViewcontrollerA.I am not able to understand the reason.
Please help to fix this.
As your all view controller A, B, C, D are child view controller of task view controller and when you are navigating the navigation controller of task view controller is used as it is the parent of all four controllers.
So when you do popviewcontroller it goes back to task view controller(not to any child view controller specifically). And when task view controller is appearing it reinitialises all its child view controller which sets view controller A as default child of its container view.
If you want your desired result, add the child view controllers from code in viewDidLoad of TaskViewController.
Visit Add child view controller to current view controller
After logging UIViewController, I am redirected to first item of UITabBarController. This works fine, but in my first viewcontrollers I want to push another view controller into the tabor view.This should happen while I logged in first time. In other words I want to replace the selected viewcontroller with another one. This UIViewController is not attached with Tabbar controller, I do not want to attach because it replace the first tabView item only one.
You will run into problems if you try to transition to another view controller in viewDidLoad. You should either switch the child view controllers of the tab bar controller or you can present a subview within one of the child view controllers.
When -viewDidLoad is called, the view controller is generally not presented. As such, if you try to present another controller, it will crash.
Try -viewDidAppear: if you want what you are describing.
I have a tab bar controller with multiple view controllers.
I attempt to do a method call to one of the view controllers (lets call it SomeViewController) and I realised that SomeViewController was not initialised yet.
And SomeViewControllerwill only be initialised when I click it's tab once.
So, is it possible to initialise the view controller even before the view of initialise is presented the first time?
I use
this.PresentViewController(...);
to display a modal view controller another controller.
Then on dismiss button action inside the modal view controller I call
this.DismissViewController(...);
The problem is in that application stops calling viewDidAppear methods in every other controller inside of my NavigationController until I reinitialize it. Actually the problem appears only on iPhone (iOS 5/6).
How to bring application to life after dismissing a modal view?