I have a view controller which has scroll view in it, and the scroll view has a view. So, view has a lot of buttons and labels which are being showed depending on data which comes from api. And I have a button after pressing it, I want to reload a views (it's content).
one of the easy hack and NOT the recommended way is to do
self.view.setNeedsLayout()
also you can do self.viewDidLoad()
OR self.viewWillAppear(true)
well the different recommended approaches you can use are the following
Delegation KVO Notifications
The other way would be to use a tableView and user reloadData()
Delegation: https://www.andrewcbancroft.com/2015/04/08/how-delegation-works-a-swift-developer-guide
KVO: https://cocoacasts.com/key-value-observing-kvo-and-swift-3/
Notifications: http://dev.iachieved.it/iachievedit/notifications-and-userinfo-with-swift-3-0/
The best and proper way is to define a method that will layout each buttons, telling if it should be hidden or display and update its frame.
The easiest but ugly way is to use :
self.viewToReload.setNeedsLayout()
self.viewToReload.layoutIfNeeded()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With