Swift 我只希望滑动删除以处理案例:0,而不是案例:1-分段控件
在我的应用程序中,我的分段控件中有要删除的滑动,它通过显示两个不同的表视图来工作,但我只想让要删除的滑动在我的案例0中工作,而不是在我的案例1中工作(因为案例1包含当前用户无法删除的其他用户数据) 我怎样才能做到这一点 这是我的刷卡删除和报告代码:Swift 我只希望滑动删除以处理案例:0,而不是案例:1-分段控件,swift,firebase,uitableview,uisegmentedcontrol,Swift,Firebase,Uitableview,Uisegmentedcontrol,在我的应用程序中,我的分段控件中有要删除的滑动,它通过显示两个不同的表视图来工作,但我只想让要删除的滑动在我的案例0中工作,而不是在我的案例1中工作(因为案例1包含当前用户无法删除的其他用户数据) 我怎样才能做到这一点 这是我的刷卡删除和报告代码: @available(iOS 11.0, *) func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPa
@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
}
但我认为我做错了。有人有主意吗?滑动操作是动态创建的,因此请检查
跟踪滑动操作配置中的selectedSegmentIndex
。如果索引不是0
nil
,则表示不显示滑动操作
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard mySegmentedControl.selectedSegmentIndex == 0 else { return nil }
let delete = ...
哦,是的,谢谢,我没想到!但是这只删除了片段案例1中的报告按钮(删除按钮还在吗?)