Este código es un trabajo para mí en swift4.
La respuesta de la pantalla anterior es: -
func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let TrashAction = UIContextualAction(style: .normal, title: "Trash", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Update action ...")
success(true)
})
TrashAction.backgroundColor = .red
let FlagAction = UIContextualAction(style: .normal, title: "Flag", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Update action ...")
success(true)
})
FlagAction.backgroundColor = .orange
let MoreAction = UIContextualAction(style: .normal, title: "More", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Update action ...")
success(true)
})
MoreAction.backgroundColor = .gray
return UISwipeActionsConfiguration(actions: [TrashAction,FlagAction,MoreAction])
}
Respuesta de la pantalla anterior: -
func tableView(_ tableView: UITableView,
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let closeAction = UIContextualAction(style: .normal, title: "Mark as Read", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("CloseAction ...")
success(true)
})
closeAction.backgroundColor = .blue
return UISwipeActionsConfiguration(actions: [closeAction])
}
Escriba el método Delegate tableview de la misma manera: -
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrPerson.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let personName = arrPerson[indexPath.row]
cell.textLabel?.text = personName.personName
return cell
}
Y en la vistaDidLoad
override func viewDidLoad() {
super.viewDidLoad()
tblView.delegate = self
tblView.dataSource = self
let person1 = personData(personName: "Jonny", personAge: 30)
let person2 = personData(personName: "Chandan", personAge: 20)
let person3 = personData(personName: "Gopal", personAge: 28)
arrPerson.append(person1)
arrPerson.append(person2)
arrPerson.append(person3)
}