首页 文章

滑动表格单元格以在Swift中执行操作

提问于
浏览
1

我正在开发一个应用程序,其中我在表视图中显示了一些数据 . 应该能够刷每个表格单元格以执行某些操作 . 这些操作分为三类:Ack,Close等 . “更多”类别会将许多操作列为操作表 . 这是我的代码(我还没有实现代码的功能)

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
    let ackAction:UITableViewRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Ack", handler: ackAlert)
    ackAction.backgroundColor = UIColor.orangeColor()

    let closeAction:UITableViewRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Close", handler: closeAlert)
    closeAction.backgroundColor = UIColor.blackColor()

    let moreAction:UITableViewRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More", handler: showMoreActions)
    moreAction.backgroundColor = UIColor.cyanColor()
    return [moreAction, closeAction, ackAction]
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    // NOTHING YET
}

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return true
}

但是,这会导致一些问题,我有一些问题:

1)我应该从左到右执行滑动操作 . 但是,据我所知,这个功能应该从右到左执行滑动操作,因此在右侧显示三个名为Ack,Close和More的按钮 . 是否可以使用相同的滑动模式,从左到右滑动会导致表格单元格左侧的这三个按钮?如果有,怎么样?

2)忽略问题1,我该如何实现:每个表格单元格应该能够从左到右滑动,如下所示:

enter image description here

enter image description here

enter image description here

enter image description here

当用户正在滑动表格单元格时,操作名称将以特定颜色显示在单元格的背景中 . 当用户放弃触摸时,将执行响应操作 . 我已经阅读了一些文档,教程和指南,但顺利的指导会很棒!

1 回答

相关问题