Reputation: 302
My app gets hanged if I try to add subview over another view controller which is added as subview.
Is there any way to get the view controllers which are in background of view? so that I can remove the view controllers which are in background of a view.
let viewController = UIStoryboard(name: "Common", bundle: nil).instantiateViewController(withIdentifier: "ContactOptionsDialouge") as! ContactOptionsDialouge
viewController.initializeDataBeforePresentingView(presentConatctUserBasicInfo : userBasicInfo,supportCall: checkAndEnableCallOption(callSupport: matchedUser!.callSupport), delegate: nil, isRideStarted: isRideStarted!)
self.navigationController?.view.addSubview(viewController.view)
self.navigationController?.addChildViewController(viewController)
Here is the code I am using to add view controller as subview. And the other top view controller it comes automatically when the other user accepts the ride using mqtt connection
Upvotes: 0
Views: 116
Reputation: 5655
It seems that your code is not crash free. You can use below code if it is relevant:
guard let viewController = UIStoryboard(name: "Common", bundle: nil).instantiateViewController(withIdentifier: "ContactOptionsDialouge") as? ContactOptionsDialouge else { print("viewController is nil"); return; }
guard let matchedUser = self.matchedUser else { print("matchedUser is nil"); return; }
guard let isRideStarted = self.isRideStarted else { print("isRideStarted is nil"); return; }
viewController.initializeDataBeforePresentingView(presentConatctUserBasicInfo: userBasicInfo, supportCall: checkAndEnableCallOption(callSupport: matchedUser.callSupport), delegate: nil, isRideStarted: isRideStarted)
self.view.addSubview(viewController.view)
self.addChildViewController(viewController)
Upvotes: 1
Reputation: 302
self.navigationController?.view.addSubview(viewController.view)
self.navigationController?.addChildViewController(viewController)
Adding below lines of code instead of above works fine for me :-
self.view.addSubview(viewController.view)
self.addChildViewController(viewController)
Upvotes: 0