我是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])
}
答案 0 :(得分:0)
据我所了解,按下按钮时,您想转到另一个窗口(UIViewController),因此必须创建一个segue
并在UIButton
中添加:
performSegue(withIdentifier: <YOUR_IDENTIFIER>, sender: self)