How to reload tableview from another view controller in swift

前端 未结 6 1894
后悔当初
后悔当初 2020-11-28 22:40

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

6条回答
  •  迷失自我
    2020-11-28 23:09

    You can use NotificationCenter to update your tableview.

    First add observer...

    NotificationCenter.default.addObserver(self, selector: #selector(doThisWhenNotify(notification:)), name: NSNotification.Name(rawValue: "load"), object: nil)
    
    func doThisWhenNotify(notification : NSNotification) {
        let info = notificatio.userInfo
        //update tableview
    
    }
    

    Post on other ViewController

    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil, userInfo: [String : Any])
    

提交回复
热议问题