In my app i have swipe to delete in my segmented control and it works by showing two different tableviews, but i only want to have the swipe to delete and report to display in my case 0, and not in my case 1 (because case 1 contains other users data that the currentuser cant be able to delete or report).
I have tried using:
if mySegmentedControl.selectedSegmentIndex == 0 {
return UISwipeActionsConfiguration(actions: [delete, report])
}
else {
return nil
}
But this only removed the report button, and not the delete button? Why is this?
This is my swipe to delete and report code :
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) ->
UISwipeActionsConfiguration? {
let delete = UIContextualAction(style: .destructive, title: "Delete") { (action, view, nil) in
Database.database().reference().child("messages").child(self.currentUserID!).child(self.message[indexPath.row].messageID).setValue([])
}
let report = UIContextualAction(style: .destructive, title: "Report") { (action, view, nil) in
let areUSureAlert = UIAlertController(title: "Are you sure you want to report?", message: "This will block this user from message you.", preferredStyle: UIAlertControllerStyle.alert)
areUSureAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in
Database.database().reference().child("messages").child(self.currentUserID!).child(self.message[indexPath.row].messageID).setValue([])
let blockedPost = ["timestamp" : [".sv" : "timestamp"]]
Database.database().reference().child("blocked").child(self.currentUserID!).child(self.message[indexPath.row].fromID).setValue(blockedPost)
}))
areUSureAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
//dismiss(animated: true, completion: nil)
}))
self.present(areUSureAlert, animated: true, completion: nil)
}
report.backgroundColor = #colorLiteral(red: 0.9529411793, green: 0.8918681279, blue: 0, alpha: 1)
if mySegmentedControl.selectedSegmentIndex == 0 {
return UISwipeActionsConfiguration(actions: [delete, report])
}
else {
return nil
}
}