ios - swift 3 : Swipe to 'Flag' , 如何

标签 ios iphone swift xcode

我有一些本质上工作正常的代码。当我向左滑动时,我会看到标志按钮,当我点击该按钮时,字符串“Flag button tapped”会打印到控制台。所以基础知识已经到位。

但是...我想将单元格标记为“已标记”,而不是仅将其打印到控制台。非常类似于 Iphone 上的 Apple 邮件应用程序,

我使用这个函数来创建滑动按钮:

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

let flag = UITableViewRowAction(style: .normal, title: "Flag") {
action, index in

    print("Flag button tapped")

    }
    flag.backgroundColor = UIColor.orange

    return [flag]
}

关于如何实现这一点有什么想法吗?欢迎任何意见。

最佳答案

您应该在最左侧的单元格中添加一个round view。然后你可以根据你的要求设置它的颜色。如果您标记某行,则将此 View 的背景色设置为橙色,如果未标记,则将其背景色设置为透明色!

关于ios - swift 3 : Swipe to 'Flag' , 如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44021420/

相关文章:

iphone - 从 CGBitmapContextGetData 返回的 void* 是什么?

ios - 在 UICollectionView (SWIFT) 中设置默认单元格?

ios - 返回 iOS 设备型号

ios - 从url获取主要内容

ios - Xcode 错误 "Can' t 安装应用程序 ... [appname].app 需要 [devicename] 不支持的 "z"功能

iphone - 从 iOS 应用调用 Lua 脚本

ios - 自定义单元格标签和按钮仅在点击时出现

objective-c - 无法将表达式的类型 int 转换为类型 void swift

ios - 为什么在调用scrollToRow时重新加载数据会导致崩溃?

ios - 如何在 iOS 中解析从 HTTP POST 输出的 JSON 字符串