未在 UITableView Swift 4 的主要滑动操作中显示标题
Posted
技术标签:
【中文标题】未在 UITableView Swift 4 的主要滑动操作中显示标题【英文标题】:Not displaying the title in leading swipe actions for UITableView Swift 4 【发布时间】:2020-05-12 09:50:00 【问题描述】:我在 tableview 中添加了两个动作领先的滑动动作,但只有背景显示,标题不可见。
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
let card = savedCards[indexPath.row]
// if !card.isDefault
let makeDefault = UIContextualAction(style: .normal, title: "Make as Default") (action, sourceView, completionHandler) in
print("index path of default: \(indexPath)")
let closeAction = UIContextualAction(style: .normal, title: "Mark as Read", handler: (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("CloseAction ...")
success(true)
)
closeAction.backgroundColor = .blue
let swipeActionConfig = UISwipeActionsConfiguration(actions: [makeDefault,closeAction])
swipeActionConfig.performsFirstActionWithFullSwipe = true
return swipeActionConfig
//
return nil
【问题讨论】:
【参考方案1】:func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
let makeDefault = UIContextualAction(style: .normal, title: "Make as Default") (action, sourceView, completionHandler) in
print("index path of default: \(indexPath)")
let closeAction = UIContextualAction(style: .normal, title: "Mark as Read", handler: (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("CloseAction ...")
success(true)
)
closeAction.backgroundColor = .blue
let swipeActionConfig = UISwipeActionsConfiguration(actions: [makeDefault,closeAction])
swipeActionConfig.performsFirstActionWithFullSwipe = true
return swipeActionConfig
【讨论】:
以上是关于未在 UITableView Swift 4 的主要滑动操作中显示标题的主要内容,如果未能解决你的问题,请参考以下文章
来自html字符串的iOS Swift 4图像未在WKWebView中加载
编辑- UITableView 单元格按钮动作委托- Swift 4