Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push View Controller from Presenting View Controller [closed]

I have a view controller that presents a table view controller modally. In the didSelectRowAt method of the presented table view controller I instantiate another view controller. I want to dismiss the presented view controller and have the presenting view controller push this new view controller.

Can I use this in some way?

self.presentingViewController?.navigationController?.pushViewController(newVC, animated: true)
like image 626
raginggoat Avatar asked Mar 22 '26 01:03

raginggoat


1 Answers

I want to dismiss the presented view controller and have the presenting view controller push this new view controller.

A modal view controller usually represents some sort of question, like What photo do you want to see? or Which contact do you want to talk to? The modal view controller should let the user indicate an answer, and then it should return that answer to its parent, the presenting controller. That presenting view controller is the one that should be in charge of what to do next. Dismiss the modal controller? Adjust the data model? Push a new controller onto the navigation stack?

Think of the relationship between the presenting view controller and the modal controller as an employment agreement, where the presenting controller is a manager and the modal controller is a worker. The worker might do some task at the manager's request and then report back, so that the manager can decide what to do next. But a worker wouldn't tell the manager what to do -- that's not the worker's job.

like image 120
Caleb Avatar answered Mar 24 '26 13:03

Caleb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!