ios – How to Refresh UITableView after getting data from NotificationCenter?

0
48


**I have Implemented Notificationcenter for Broadcasting data from Delegate page**



   override func viewWillAppear(_ animated: Bool) {
            NotificationCenter.default.addObserver(self, selector: #selector(self.handleNotification1(withNotification1:)), name: NSNotification.Name(rawValue:"id"), object: nil)
          
        }

I want to call gettenantlistforattendance() function with an API, which have to append array data in tableview array’s

@objc func handleNotification1(withNotification1 notification : NSNotification) {
    guard let userInfo = notification.userInfo,
        let i = userInfo[AnyHashable("fireDrillId")]! as? String else {
            print("No userInfo found in notification")
            return
    }
    print("data  :: \(userInfo["fireDrillId"])")
    let fireID = userInfo["fireDrillId"] as? Int
    print("getting id \(fireID ?? 0)")
    gettenantlistforattendance() //the problem is here in that function i have reload tableview but still not able to refresh tableview data
}

**The code i have implemented in gettenantlistforattendance() for append array and reload tableview is **

     for arr in tenantList.arrayValue{
                                             self.arrData.append(TernantList_Attendance_Model(json: arr))
                     
}
DispatchQueue.main.async {
                                             self.presentCountlbl.text = self.totalpresent
self.absentCountlbl.text = self.totalabsent
self.missingCountlbl.text = self.totalmissing                                       self.tableviewAttendance.reloadData()                                             self.tableviewAttendance.separatorStyle = .none
}