Я хотел бы отобразить данные, которые приходят после вызова webservice.
Когда я вызываю webservice, я отображаю загрузчик SVProgress, пока не придет ответ.
Когда приходит ответ, я закрываю загрузчик и отображаю данные в виде таблицы.Работает нормально.Но когда я снова открываю приложение, загрузчик времени рано отключается, а просмотр таблицы занимает больше времени для отображения данных.
Я попытался перезагрузить UITableView
в главном потоке после получения ответа, но все равно не работает.
let cellReuseIdentifier = "HomeTableViewCell"
let tableViewCell = UINib(nibName: "HomeTableViewCell", bundle: nil)
self.tableView.register(tableViewCell, forCellReuseIdentifier: cellReuseIdentifier)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : HomeTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as! HomeTableViewCell
cell.backgroundColor = UIColor.clear
var objemail = self.arrayData.object(at: indexPath.row) as? NewHomeModel
if objemail?.unread == 1 {
cell.lblEmailSender.textColor = UIColor.black
cell.lblEmailDescription.textColor = UIColor.black
}else{
cell.lblEmailSender.textColor = UIColor.gray
cell.lblEmailDescription.textColor = UIColor.gray
}
if objemail?.fileStatus == 1 {
cell.imgAttachment.isHidden = false
}else{
cell.imgAttachment.isHidden = true
}
cell.lblEmailSender.text = objemail?.from
cell.lblEmailHeading.text = objemail?.subject
cell.lblEmailDescription.text = objemail?.body
let timestamparray = objemail?.date?.components(separatedBy: " ")
cell.lblEmailDate.text = timestamparray![1]
cell.btnPaid.accessibilityHint = objemail?.thread_id
cell.btnPending.accessibilityHint = objemail?.thread_id
cell.btnDispute.accessibilityHint = objemail?.thread_id
var pending = objemail?.pending
if (pending == 0) {
self.rowIndexpath = indexPath
cell.btnPending.setBackgroundImage(UIImage(named: "pending_disable_icon"), for: UIControl.State.normal)
cell.btnPending.addTarget(self, action: #selector(HomeViewController.penddingClick(_:)), for:.touchUpInside )
cell.btnPending.add(for: .touchUpInside) {
pending = 1
cell.btnPending.setBackgroundImage(UIImage(named: "pending_active_icon"), for: UIControl.State.normal)
cell.btnPaid.setBackgroundImage(UIImage(named: "paid_disable_icon"), for: UIControl.State.normal)
cell.btnDispute.setBackgroundImage(UIImage(named: "dispute_disable_icon"), for: UIControl.State.normal)
}
}
else
{
cell.btnPending.setBackgroundImage(UIImage(named: "pending_active_icon"), for: UIControl.State.normal)
cell.btnPending.add(for: .touchUpInside) {
pending = 0
cell.btnPending.setBackgroundImage(UIImage(named: "pending_active_icon"), for: UIControl.State.normal)
cell.btnPaid.setBackgroundImage(UIImage(named: "paid_disable_icon"), for: UIControl.State.normal)
cell.btnDispute.setBackgroundImage(UIImage(named: "dispute_disable_icon"), for: UIControl.State.normal)
}
}
if objemail?.dispute == 0 {
cell.btnDispute.setBackgroundImage(UIImage(named: "dispute_disable_icon"), for: UIControl.State.normal)
cell.btnDispute.addTarget(self, action: #selector(HomeViewController.disputeClick(_:)), for:.touchUpInside )
cell.btnDispute.add(for: .touchUpInside) {
objemail?.dispute = 1
cell.btnPending.setBackgroundImage(UIImage(named: "pending_disable_icon"), for: UIControl.State.normal)
cell.btnPaid.setBackgroundImage(UIImage(named: "paid_disable_icon"), for: UIControl.State.normal)
cell.btnDispute.setBackgroundImage(UIImage(named: "dispute_active_icon"), for: UIControl.State.normal)
}
}
else
{
cell.btnDispute.setBackgroundImage(UIImage(named: "dispute_active_icon"), for: UIControl.State.normal)
cell.btnDispute.add(for: .touchUpInside) {
cell.btnPending.setBackgroundImage(UIImage(named: "pending_disable_icon"), for: UIControl.State.normal)
cell.btnPaid.setBackgroundImage(UIImage(named: "paid_disable_icon"), for: UIControl.State.normal)
cell.btnDispute.setBackgroundImage(UIImage(named: "dispute_active_icon"), for: UIControl.State.normal)
}
}
if(objemail?.paid == 0)
{
cell.btnPaid.setBackgroundImage(UIImage(named: "paid_disable_icon"), for: UIControl.State.normal)
cell.btnPaid.addTarget(self, action: #selector(HomeViewController.paidClick(_:)), for:.touchUpInside )
cell.btnPaid.add(for: .touchUpInside) {
cell.btnPending.setBackgroundImage(UIImage(named: "pending_disable_icon"), for: UIControl.State.normal)
cell.btnPaid.setBackgroundImage(UIImage(named: "paid_active_icon"), for: UIControl.State.normal)
cell.btnDispute.setBackgroundImage(UIImage(named: "dispute_disable_icon"), for: UIControl.State.normal)
}
}
else
{
cell.btnPaid.setBackgroundImage(UIImage(named: "paid_active_icon"), for: UIControl.State.normal)
cell.btnPaid.add(for: .touchUpInside) {
cell.btnPending.setBackgroundImage(UIImage(named: "pending_disable_icon"), for: UIControl.State.normal)
cell.btnPaid.setBackgroundImage(UIImage(named: "paid_active_icon"), for: UIControl.State.normal)
cell.btnDispute.setBackgroundImage(UIImage(named: "dispute_disable_icon"), for: UIControl.State.normal)
}
}
return cell
}
func callWSGmailMessages() -> Void {
guard let id = UserDefaults.standard.string(forKey: "id") else { return }
guard let email_Account_Id = UserDefaults.standard.string(forKey: "email_account_id") else { return }
guard let nextToken = UserDefaults.standard.string(forKey: "nextToken") else { return }
let parameters = ["app_user_id": id,"email_account_id" : email_Account_Id,"next_page_token":nextToken]
let api = NetworkApiManager()
api.postReuestData(baseUrl: API.GMAIL_MESSAGES, params: parameters , result: { (result) in
guard let dicData = (result as AnyObject) as? NSDictionary else { return }
guard let dict = dicData.object(forKey: "message") as? NSDictionary else { return }
guard let dictTemp = dict.object(forKey: "profile") as? NSDictionary else { return }
UserDefaults.standard.set(dictTemp.value(forKey: "name"), forKey: "UserName")
UserDefaults.standard.set(dictTemp.value(forKey: "picture"), forKey: "profileImage")
NotificationCenter.default.post(name: Notification.Name("NotificationIdentifier"), object: nil)
guard let nextToken1 = UserDefaults.standard.string(forKey: "nextToken") else { return }
if nextToken1 == " "
{
self.arrayData .removeAllObjects()
}
let emailAccountId = dictTemp.object(forKey:"email_account_id")
UserDefaults.standard.set(emailAccountId, forKey: "email_account_id")
UserDefaults.standard.set(true, forKey: "is_present_email_list")
guard let arrMessages = dicData.value(forKeyPath:"message.messages") as? NSArray else{
return
}
self.lblNoEmail.isHidden = true
self.bRequest = false
let nextToken = (dicData.value(forKeyPath:"message.nextToken") as Any) as AnyObject
UserDefaults.standard.set(nextToken, forKey: "nextToken")
for i in 0..<arrMessages.count{
let dictNew = arrMessages.object(at: i) as! NSDictionary
let objemail = NewHomeModel.init(jsonData: dictNew as! [String : Any])
self.arrayData.add(objemail)
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}, failError: { (error) in
Singleton.sharedInstance.ShowAlert(title: API.TITLE, message: error.localizedDescription, in: self)
return
}, resultWithError: {(resultWithError) in
guard let dicData = (resultWithError as AnyObject) as? NSDictionary
else{
Singleton.sharedInstance.ShowAlert(title: API.TITLE, message: "Error Data", in: self)
return
}
Singleton.sharedInstance.ShowAlert(title: API.TITLE, message: dicData.value(forKeyPath: "error.message") as! String, in: self)
})
}