Swift 3: UITableViewRowActionStyle() “Missing Parameter” Error Msg

亡梦爱人 提交于 2019-12-19 07:49:08

问题


When I swipe a UITableView cell, the below code is called:

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

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

Now that I've started migrating to Swift 3, I get an error message on the UITableViewRowActionStyle():

Missing argument for parameter 'rawValue' in call

Anyone know what the syntax for Swift 3 is in this situation?


回答1:


Default initializers are removed from some imported enum types in Swift 3.

Use UITableViewRowActionStyle.default (or in your case simply .default) instead of UITableViewRowActionStyle().

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



回答2:


Use UITableViewRowActionStyle as if its an enum. If you type it you will see multiple options:

UITableViewRowActionStyle.Default
UITableViewRowActionStyle.Destructive
UITableViewRowActionStyle.Normal 

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

Some times only "special" cases are provided in this manner ... and you have to use rawValue: 0 in order to denote default behavior



来源:https://stackoverflow.com/questions/39338480/swift-3-uitableviewrowactionstyle-missing-parameter-error-msg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!