【问题标题】:Swift 3: UITableViewRowActionStyle() "Missing Parameter" Error MsgSwift 3:UITableViewRowActionStyle()“缺少参数”错误消息
【发布时间】:2016-09-05 22:44:04
【问题描述】:

当我滑动 UITableView 单元格时,会调用以下代码:

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {

    //Problem code
    let delBut = UITableViewRowAction(style: UITableViewRowActionStyle(), title: delete_InLocal) { action, index in
        //Setup

现在我已经开始迁移到 Swift 3,我在 UITableViewRowActionStyle() 上收到一条错误消息:

调用中的参数“rawValue”缺少参数

有人知道在这种情况下 Swift 3 的语法是什么吗?

【问题讨论】:

    标签: ios uitableview swift3 uitableviewrowaction


    【解决方案1】:

    在 Swift 3 中从一些导入的枚举类型中删除了默认初始化器。

    使用UITableViewRowActionStyle.default(或者在你的情况下只是.default)而不是UITableViewRowActionStyle()

        let delBut = UITableViewRowAction(style: .default, title: delete_InLocal) { action, index in
    

    【讨论】:

      【解决方案2】:

      像使用枚举一样使用 UITableViewRowActionStyle。如果你输入它,你会看到多个选项:

      UITableViewRowActionStyle.Default
      UITableViewRowActionStyle.Destructive
      UITableViewRowActionStyle.Normal 
      
      let delBut = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: delete_InLocal) { action, index in
      }
      

      有时仅以这种方式提供“特殊”情况...您必须使用 rawValue: 0 来表示默认行为

      【讨论】:

      • 从 Xcode 8 beta 6 开始,枚举案例应该以小写字母开头UITableViewRowActionStyle.destructive
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多