Reload collection view data from another view class

前端 未结 3 993
一生所求
一生所求 2020-12-25 10:23

I have two containers in a view. The top one has a collection view. I want to update my collection view from a button when a button is hit from the below container. My butto

3条回答
  •  庸人自扰
    2020-12-25 10:54

    Swift 4:

    1st class:

    NotificationCenter.default.post(name: NSNotification.Name("load"), object: nil)
    

    Class with collectionView:

    in viewDidLoad():

    NotificationCenter.default.addObserver(self, selector: #selector(loadList(notification:)), name: NSNotification.Name(rawValue: "load"), object: nil)
    

    and function:

    @objc func loadList(notification: NSNotification) {
      self.collectionView.reloadData()
    }
    

提交回复
热议问题