SwipeCellKit 动作不会执行 segue
SwipeCellKit action won't perform segue
我正在为我的待办事项列表应用程序使用 SwipeCellKit。当用户向左滑动时它会删除该项目,但是当用户向右滑动时我希望他能够在该项目上设置提醒,所以我创建了一个动作set a reminder
此操作应执行一个 segue,将用户带到一个带有日期选择器的自定义弹出窗口。问题是,当我单击按钮设置提醒时,模拟器退出并出现未捕获的异常。我已经尝试从这个按钮执行删除它完美地工作,我还尝试从模拟器退出的这个按钮执行到另一个视图控制器的另一个 segue。有人可以告诉我我在这里做错了什么吗?这是我的代码:
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? { if orientation == .left {
guard isSwipeRightEnabled else { return nil }
let setReminder = SwipeAction(style: .default, title: "Set a reminder") { action, indexPath in
self.updateModelByAddingAReminder(at: indexPath)
}
setReminder.image = UIImage(named: "reminder-icon")
return[setReminder]
}else{
let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
self.updateModel(at: indexPath)
}
// customize the action appearance
deleteAction.image = UIImage(named: "delete-icon")
// return [setReminder, deleteAction]
return [deleteAction]
}
好的,我发现你的手机选项有问题。
来自文档
内置的 .destructive 和 .destructiveAfterFill 扩展样式被配置为在调用操作处理程序时自动执行行删除(自动实现)。
并且您需要在 editActionsForRowAt 中对单元格使用破坏性样式。或者使用其他选项,例如
func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeTableOptions {
var options = SwipeTableOptions()
options.transitionStyle = .border
if orientation == .left{
//or none
options.expansionStyle = .selection
}else{
options.expansionStyle = .destructive
}
return options
}
希望对您有所帮助。
我正在为我的待办事项列表应用程序使用 SwipeCellKit。当用户向左滑动时它会删除该项目,但是当用户向右滑动时我希望他能够在该项目上设置提醒,所以我创建了一个动作set a reminder
此操作应执行一个 segue,将用户带到一个带有日期选择器的自定义弹出窗口。问题是,当我单击按钮设置提醒时,模拟器退出并出现未捕获的异常。我已经尝试从这个按钮执行删除它完美地工作,我还尝试从模拟器退出的这个按钮执行到另一个视图控制器的另一个 segue。有人可以告诉我我在这里做错了什么吗?这是我的代码:
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? { if orientation == .left {
guard isSwipeRightEnabled else { return nil }
let setReminder = SwipeAction(style: .default, title: "Set a reminder") { action, indexPath in
self.updateModelByAddingAReminder(at: indexPath)
}
setReminder.image = UIImage(named: "reminder-icon")
return[setReminder]
}else{
let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
self.updateModel(at: indexPath)
}
// customize the action appearance
deleteAction.image = UIImage(named: "delete-icon")
// return [setReminder, deleteAction]
return [deleteAction]
}
好的,我发现你的手机选项有问题。 来自文档 内置的 .destructive 和 .destructiveAfterFill 扩展样式被配置为在调用操作处理程序时自动执行行删除(自动实现)。 并且您需要在 editActionsForRowAt 中对单元格使用破坏性样式。或者使用其他选项,例如
func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeTableOptions {
var options = SwipeTableOptions()
options.transitionStyle = .border
if orientation == .left{
//or none
options.expansionStyle = .selection
}else{
options.expansionStyle = .destructive
}
return options
}
希望对您有所帮助。