iOS reloading a UITableView from a Swift class/object

前端 未结 3 1866
难免孤独
难免孤独 2020-12-17 02:53

I am trying to build a object oriented iOS app and I am having problems calling a table reload (ui interaction) from one of my swift class files.

If I am working wit

3条回答
  •  庸人自扰
    2020-12-17 02:56

    You can just post a Notification when your async task finishes:

    NSNotificationCenter.defaultCenter().postNotificationName("refreshMyTableView", object: nil)
    

    Add an observer to that notification to your DeviceOverview class method viewDidLoad:

    NSNotificationCenter.defaultCenter().addObserver(self, selector: "refreshList:", name:"refreshMyTableView", object: nil) 
    

    and add the method that will be fired at your DeviceOverview class

    func refreshList(notification: NSNotification){
        myTableView.reloadData()
    }
    

提交回复
热议问题