如何在 TAP 上编辑 tableview 单元格而不是滑动 - Swift [英] How to edit tableview cell on TAP instead of swipe - Swift

查看:19
本文介绍了如何在 TAP 上编辑 tableview 单元格而不是滑动 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableViewController,目前,用户可以在单元格上向左滑动以显示添加到收藏夹"按钮.我现在想向单元格添加一个图标,用户可以点击该图标以显示此按钮(与向左滑动相同).对于不知道向左滑动会做同样事情的用户来说,这只是一种视觉辅助.

I have a UITableViewController and at the moment, the user can swipe left on the cell to reveal an 'add to favourites' button. I would now like to add an icon to the cell that the user can tap to reveal the this button (does the same thing as swiping to the left). This will just act as a visual aid for the users who do not know swiping left will do the same thing.

对于我的 TableView,我使用以下代码在用户按下按钮时关闭单元格":

For my TableView, I use the following code to 'close the cell' when the user has pressed the button:

itemsTableView.setEditing(false, animated: true)

由此,我假设要手动打开单元格,我只需调用:

From this I assumed that to manually open the cell I would simply call:

//Get cell
let cell:TableViewCell = itemsTableView.cellForRowAtIndexPath(NSIndexPath(forRow: 
sender.tag, inSection: 0)) as! TableViewCell 

//Open cell to reveal button
cell.setEditing(true, animated: true)

不幸的是,这不起作用.所以我想知道当用户向单元格左侧滑动时调用的函数是什么,当用户点击图标时如何复制它?

Unfortunately this does not work. So I would like to know what is the function that is called when a user swipes to the left of a cell and how can I replicate it when a user taps on the icon?

推荐答案

我不认为你能做到,抱歉.此功能依赖于 UITableView 的平移手势识别器.当用户横向平移时,表格视图检查 editActions... 委托方法,如果我们有编辑操作,则在单元格后面插入一个私有确认视图并允许移动单元格以显示它.据我所知,您无法以编程方式触发该行为.

I don't think you're going to be able to do it, sorry. This feature relies on the UITableView's pan gesture recognizer. When the user pans sideways, the table view checks the editActions... delegate method and, if we have edit actions, inserts a private confirmation view behind the cell and allows the cell to be moved to reveal it. You can't trigger that behavior programmatically as far as I can tell.

这将是坚持使用第三方可滚动单元格类的一个原因——许多非常好的原因之一.这样,单元格是一个水平滚动视图,您只需在代码中滚动它.

This would be a reason — one of many very good reasons — for sticking with a third-party scrollable cell class. In this way, the cell is a horizontal scroll view and you just scroll it in code.

这篇关于如何在 TAP 上编辑 tableview 单元格而不是滑动 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆