【问题标题】:Edit Button - Swift - UIViewController编辑按钮 - Swift - UIViewController
【发布时间】: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


【解决方案1】:

据我了解,按下按钮时,您想转到另一个窗口 (UIViewController),因此您必须创建一个 segue 并在您的 UIButton 添加:

performSegue(withIdentifier: <YOUR_IDENTIFIER>, sender: self)

【讨论】:

  • 当我尝试这个时,我得到了错误:无法将'AddfreshreleaseViewController.Type'类型的值转换为预期的参数类型'String'
  • 没关系,我给 UIViewController 一个标题来修复这个错误。它现在可以构建,但是当我滑动该按钮时,应用程序崩溃了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-13
  • 2022-11-11
  • 2019-06-29
  • 2011-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多