如何从swift中的另一个视图控制器重新加载tableview [英] How to reload tableview from another view controller in swift
本文介绍了如何从swift中的另一个视图控制器重新加载tableview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我解雇一个模态视图控制器时我希望tableview更新,我在iPad上使用表单表示样式,所以 viewWillAppear
和 viewDidAppear
方法不起作用
When I dismiss a modal view controller I want the tableview to update, I am using the form sheet presentation style on iPad so the viewWillAppear
and the viewDidAppear
methods will not work
推荐答案
Swift 3版本代码:
在你的第一个view controller:
Swift 3 version code: In your first view controller:
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(loadList), name: NSNotification.Name(rawValue: "load"), object: nil)
}
func loadList(){
//load data here
self.tableView.reloadData()
}
在第二个视图控制器中:
In your second view controller:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil)
这篇关于如何从swift中的另一个视图控制器重新加载tableview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文