我做了一个自定义的UITableViewRowAction.现在我想添加一个图像而不是文本.我知道这是可能的,但不知道该怎么做.你们中的某些人是否知道如何在Swift中做到这一点并想帮助我?谢谢你的回答!
目前我正在使用NSFetchedResultsController来处理表视图.我想知道有没有办法在滑动操作中添加其他按钮,如删除按钮?
我正在考虑将其子类化.但是在帮助文档中找不到与我的问题相关的内容.
提前致谢.
你能告诉我,在UITableview上滑动单元格时如何添加自定义图像来删除按钮?
所以我在网站上搜索了这个问题的答案,有一些不错的结果,但最近没有任何结果,因为 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 上定义“右滑动”?
在我的应用程序中,我的类定义如下:
class MyTableViewController: UITableViewController {
Run Code Online (Sandbox Code Playgroud)
在里面我想添加刷选所选单元格的功能(取自这个答案)
但是当我在那里写这个:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let more = UITableViewRowAction(style: .Normal, title: "More") { action, index in
print("more button tapped")
}
more.backgroundColor = UIColor.lightGrayColor()
let favorite = UITableViewRowAction(style: .Normal, title: "Favorite") { action, index in
print("favorite button tapped")
}
favorite.backgroundColor = UIColor.orangeColor()
let share = UITableViewRowAction(style: .Normal, title: "Share") { action, index in
print("share button tapped")
}
share.backgroundColor = UIColor.blueColor()
return [share, favorite, more]
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
使用Objective-C选择器的方法'tableView( …
我有一个TableView,它已被编码为在使用该didSelectRowAt方法选择的任何单元格时执行操作.
现在,我想向表格(或单元格)添加一个向左滑动手势,这样我可以在滑动单元格时执行辅助操作,而不是轻敲单元格.
1)我希望细胞在滑动时向左移动,但我不想在细胞移动的空间中添加按钮.
2)相反,我希望能够将单元格"拖动"到某个点(比如说中途),然后用indexPath执行辅助操作(所以我知道哪个单元被拖动).
3)如果用户停止拖动或放开单元格,我希望它返回到它的起始位置并且不会发生任何操作.
我已经看过很多样本可以做各种各样的部分但是大多数都在Obj-C中,或者在与单元格相同的行中插入按钮.
另外,将Gesture添加到每个单元格中会更好吗?将它添加到表中似乎更聪明......
编辑:请参阅下面的代码完整答案