【发布时间】:2018-07-25 03:47:23
【问题描述】:
我是 Swift 语言的新手,以及一般的编码。我在使用代码时写了一个编辑按钮:
{
let modifyAction = UIContextualAction(style: .normal, title: "Update", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Update action ...")
success(true)
})
modifyAction.title = "Edit"
modifyAction.backgroundColor = .blue
return UISwipeActionsConfiguration(actions: [modifyAction])
}
按下时,我需要编辑按钮才能转到此 UIViewController:
AddfreshreleaseViewController: UIViewController
我该怎么写呢?
更新
我正在尝试将编辑按钮链接回我的 UIViewController (AddfreshreleaseViewController)。当您向右滑动单元格时,此代码会在左侧显示编辑按钮,但是当我在“performSegue”中添加以尝试返回 UIViewController 时,应用程序会在我现在每次向编辑按钮滑动时崩溃。关于如何让这个工作的任何建议?
@available(iOS 11.0, *)
override func tableView(_ tableView: UITableView,
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let modifyAction = UIContextualAction(style: .normal, title: "Update", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Update action ...")
success(true)
})
modifyAction.title = "Edit"
modifyAction.backgroundColor = .blue
performSegue(withIdentifier: "addFreshRelease", sender: self)
return UISwipeActionsConfiguration(actions: [modifyAction])
}
【问题讨论】:
-
嘿...您尝试过解决方案吗?
-
我做到了,您的代码很有帮助!但是当我向右滑动单元格时,我希望这个按钮出现。所以,除了我已经必须让按钮显示的代码之外,我不确定如何在视图中设置它。
-
应该作为不同的问题提出。
-
好吧,我提供的代码使得当您向右滑动单元格时,它会显示一个编辑按钮。我只是不知道如何让那个编辑按钮带你回到 AddfreshreleaseViewController 页面。
标签: swift uitableview uiviewcontroller edit