[英]reload tableView from Another ViewController Swift 4.2
when i am trying to call method from another VC reloadData()
then the app crash Fatal error: Unexpectedly found nil while unwrapping an Optional value
due to tablview nil how can resolve it. 当我试图从另一个VC reloadData()
调用方法然后应用程序崩溃Fatal error: Unexpectedly found nil while unwrapping an Optional value
由于tablview nil Fatal error: Unexpectedly found nil while unwrapping an Optional value
而Fatal error: Unexpectedly found nil while unwrapping an Optional value
nil如何解决它。
FavoritesFiltersViewController.shareInstance.reloadData()
Check the init function that's triggered when you call FavoritesFiltersViewController.shareInstance
It seems that you are not giving a value to the tableView property. 检查调用FavoritesFiltersViewController.shareInstance
时触发的init函数看来你没有给tableView属性赋值。
Just to check, you can remove the optional from it and see if the compiler complains because it has no initial value. 只是要检查,你可以从中删除可选项,看看编译器是否抱怨,因为它没有初始值。
1. You can add this line to another viewController. 1.您可以将此行添加到另一个viewController。
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "newDataNotif"), object: nil)
2. Add this line(viewDidLoad) to viewController where contain tableView. 2.将此行(viewDidLoad)添加到包含tableView的viewController。
NotificationCenter.default.addObserver(self, selector: #selector(self.refresh), name: NSNotification.Name(rawValue: "newDataNotif"), object: nil)
3. Add this selector method for reload tableView data. 3.添加此选择器方法以重新加载tableView数据。
@objc func refresh() {
self.tblview.reloadData() // a refresh the tableView.
}
This is working fine. 这工作正常。 Thank you. 谢谢。
Thanks for every one.Finally after a R&D. 感谢每一个人。最后研发后。 i found the following solution. 我找到了以下解决方案。 and its working fine. 它的工作正常。
let fav:FavoritesFiltersViewController!
fav.reloadData()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.