gpt4 book ai didi

swift - 分段控制 - 为什么在检查 .selectedSegmentIndex 时两个滑动操作都不会消失

转载 作者:行者123 更新时间:2023-11-30 11:05:08 25 4
gpt4 key购买 nike

在我的应用程序中,我在分段控件中可以滑动删除,它通过显示两个不同的表格 View 来工作,但我只想在我的情况 0 中显示滑动删除和报告,而不是在我的情况 1 中显示(因为情况 1 包含当前用户无法删除或报告的其他用户数据)。

我尝试过使用:

if mySegmentedControl.selectedSegmentIndex == 0 {
return UISwipeActionsConfiguration(actions: [delete, report])
}
else {
return nil
}

但这只是删除了报告按钮,而没有删除按钮?为什么是这样?

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

@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
}

}

最佳答案

在这里找到解决方案:Delete button is automatically implemented on swipe despite not implementing trailing swipe action in tableview

通过实现:

return UISwipeActionsConfiguration.init()

而不是

return nil

关于swift - 分段控制 - 为什么在检查 .selectedSegmentIndex 时两个滑动操作都不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52813205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com