我希望滑动删除仅适用于案例:0 而不是案例:1 - 分段控件



在我的应用程序中,我在我的分段控件中滑动以删除,它通过显示两个不同的表视图来工作,但我只想让滑动删除在我的案例 0 中工作,而不是在我的案例 1 中工作(因为案例 1 包含当前用户无法删除的其他用户数据。

我怎样才能做到这一点?

这是我滑动删除和报告代码:

@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)
return UISwipeActionsConfiguration(actions: [delete, report])
}

我试过打电话

switch(mySegmentedControl.selectedSegmentIndex) {
case 0:
//do all the report and swipe in here
case 1:
break

default:
break
}

但我认为我做错了..有人有想法吗?

滑动操作是动态创建的,因此请检查trailingSwipeActionsConfigurationForRowAt中的selectedSegmentIndex。如果未返回索引0nil则表示不显示轻扫操作。

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard mySegmentedControl.selectedSegmentIndex == 0 else { return nil }
let delete = ...

最新更新