hna*_*eri 4 uitableview swipe ios swift
所以我在网站上搜索了这个问题的答案,有一些不错的结果,但最近没有任何结果,因为 Xcode 7 不再是测试版,而 swift 2.0 现在是标准。
我使用了以下代码来实现“向左滑动”功能将导致 UITableViewCell 发生某些情况 -
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){
if editingStyle == UITableViewCellEditingStyle.Delete {
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,这是 Apple 现在在其 API 中提供的内容,不需要使用外部类。
我还了解您可以使用此本机代码自定义此滑动所产生的操作:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let more = UITableViewRowAction(style: .Normal, title: "More") { action, index in
print("more button tapped")
}
Run Code Online (Sandbox Code Playgroud)
是否有任何现代本机代码可以在 UITableViewCell 上定义“右滑动”?
小智 5
func tableView(_ tableView: UITableView,
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let closeAction = UIContextualAction(style: .normal, title: "Close", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("OK, marked as Closed")
success(true)
})
closeAction.image = UIImage(named: "tick")
closeAction.backgroundColor = .purple
return UISwipeActionsConfiguration(actions: [closeAction])
}
func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let modifyAction = UIContextualAction(style: .normal, title: "Update", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Update action ...")
success(true)
})
modifyAction.image = UIImage(named: "hammer")
modifyAction.backgroundColor = .blue
return UISwipeActionsConfiguration(actions: [modifyAction])
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4393 次 |
| 最近记录: |