I am using tableView editActionsForRowAt
function for swipe action. It appears, but action doesn't work. When I click the swipe action, my functions have to work, but they don't. Normally, getOnay
and loadOnaylar
are working in the other viewController
, but not here.
Here is my code :
override func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
let onay = UITableViewRowAction(style: .normal, title: "Onay") { action, index in
// these are my functions. but they don't work here.
self.getOnay(id: self.onayCode.id, status: "ok")
self.loadOnaylar(userID: self.onayCode.userId, code: self.onayCode.systemCode)
self.alertView(title: "Onaylandı!", message: "Görev onaylandı.")
}
onay.backgroundColor = .green
let ret = UITableViewRowAction(style: .normal, title: "Ret") { action, index in
self.getOnay(id: self.onayCode.id, status: "cancel")
self.loadOnaylar(userID: self.onayCode.userId, code: self.onayCode.systemCode)
self.alertView(title: "Ret edildi!", message: "Görev ret edildi.")
}
ret.backgroundColor = .red
//favorite.backgroundColor = UIColor(patternImage: UIImage(named: "redicon")!)
return [ret, onay]
}
I realized that self.onayCode.id was nil in the getOnay function. On the other hand, I wanted to get indexPath when I swipe the table row cell.
I used editActionsForRowAt.row
for getting the index. Then I got my row's id.
Here is my working code :
override func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
let onay = UITableViewRowAction(style: .normal, title: "Onay") { action, index in
let ip = editActionsForRowAt.row
let taskInfo:Task = self.onayArray[ip]
self.getOnay(id: taskInfo.id, status: "ok")
print(taskInfo.id,"< id bu")
self.loadOnaylar(userID: taskInfo.userId, code: self.onayCode.systemCode)
self.alertView(title: "Onaylandı!", message: "Görev onaylandı.")
}
onay.backgroundColor = .green
return [onay]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.