如何制作可滑动的集合视图单元格以在swift中显示删除按钮?
我有一个用这段代码删除单元格的功能
{defer, dispatch} = Turbolinks
handleEvent = (eventName, handler) ->
document.addEventListener(eventName, handler, false)
translateEvent = ({from, to}) ->
handler = (event) ->
event = dispatch(to, target: event.target, cancelable: event.cancelable, data: event.data)
event.preventDefault() if event.defaultPrevented
handleEvent(from, handler)
translateEvent from: "turbolinks:click", to: "page:before-change"
translateEvent from: "turbolinks:request-start", to: "page:fetch"
translateEvent from: "turbolinks:request-end", to: "page:receive"
translateEvent from: "turbolinks:before-cache", to: "page:before-unload"
translateEvent from: "turbolinks:render", to: "page:update"
translateEvent from: "turbolinks:load", to: "page:change"
translateEvent from: "turbolinks:load", to: "page:update"
loaded = false
handleEvent "DOMContentLoaded", ->
defer ->
loaded = true
handleEvent "turbolinks:load", ->
if loaded
dispatch("page:load")
jQuery?(document).on "ajaxSuccess", (event, xhr, settings) ->
if jQuery.trim(xhr.responseText).length > 0
dispatch("page:update")
使用此手势调用
func reset(sender: UISwipeGestureRecognizer) {
let cell = sender.view as! UICollectionViewCell
let i = self.collectionView.indexPathForCell(cell)!.item
deleteDateFromArray(i)
deleteImageFromArray(i)
deleteSinceLabelFromArray(i)
self.collectionView.reloadData() // replace favoritesCV with your own collection view.
}
但是我想要一个与邮件应用程序完全相同的手势,即在单元格上向左滑动它会显示删除按钮吗?
由于
答案 0 :(得分:0)
我不认为UICollectionView
提供了这种便利(您可能在UITableView
中看到了它)。这意味着你可能必须自己实现它。