如何重新加载 ui 视图的内容 Swift [英] How to reload a ui view's content Swift
问题描述
我有一个视图控制器,里面有滚动视图,滚动视图有一个视图.因此,视图有很多按钮和标签,这些按钮和标签根据来自 api 的数据显示.按下按钮后我有一个按钮,我想重新加载视图(它的内容).
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).
推荐答案
一种简单的 hack 并且不推荐的方法是这样做
one of the easy hack and NOT the recommended way is to do
self.view.setNeedsLayout()
你也可以做 self.viewDidLoad()
或 self.viewWillAppear(true)
你可以使用的不同推荐方法如下
well the different recommended approaches you can use are the following
委托KVO通知
另一种方法是使用 tableView 和用户 reloadData()
The other way would be to use a tableView and user reloadData()
委托: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/
通知:http://dev.iachieved.it/iachievedit/notifications-and-userinfo-with-swift-3-0/
这篇关于如何重新加载 ui 视图的内容 Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!