重新加载桌面视图和触摸手势
我有一个在添加新内容时正在重新加载的表格视图,使用 [tableview reloadData];
问题是我在表格中的 TableCells 上有一个 UILongPressGestureRecognizer,因为单元格/表格经常重新加载LongPress 并不总是有时间工作,因为我猜当重新加载单元格/表格时,它的内部计时器会被重置。
I have a tableview which is being reloaded as new content is added, using [tableview reloadData];
Trouble is I have a UILongPressGestureRecognizer on the TableCells in the Table and because the cells / table are being reloaded quite often the LongPress doesnt always have time to work as, I'm guessing it's internal timers are being reset when the cell/table is being reloaded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过在调用
[tableView reloadData]
之前查看UILongPressGestureRecognizer
的状态?例如:让我知道它是否有效!
Have you tried looking at the state of your
UILongPressGestureRecognizer
s before[tableView reloadData]
is called? For example:Let me know if it works!
如果您希望保留现有单元格,请不要使用
reloadData
。相反,当您获取新数据时,请使用 插入和删除单元格以准确通知表格视图哪些单元格已更改。一般过程是:beginUpdates
deleteRowsAtIndexPaths:withRowAnimation:
以删除新数据中已删除的任何旧项目的单元格。insertRowsAtIndexPaths:withRowAnimation:
为新数据中已添加的任何项目添加新单元格。reloadRowsAtIndexPaths:withRowAnimation:
。UITableViewDataSource
方法必须反映新数据(例如tableView:numberOfRowsInSection:
应反映更改后的计数,而tableView:cellForRowAtIndexPath:
应使用新项目)。Don't use
reloadData
if you want existing cells to remain. Instead, when you get new data, use the methods for Inserting and Deleting Cells to inform the table view exactly which cells have changed. The general procedure is:beginUpdates
deleteRowsAtIndexPaths:withRowAnimation:
to remove cells for any old items that have been deleted in the new data.insertRowsAtIndexPaths:withRowAnimation:
to add new cells for any items that have been added in the new data.reloadRowsAtIndexPaths:withRowAnimation:
.commitUpdates
. At this point, yourUITableViewDataSource
methods must reflect the new data (e.g.tableView:numberOfRowsInSection:
should reflect the changed count, andtableView:cellForRowAtIndexPath:
should use the new items).当您触摸单元格时,将 aCellIsSelected 之类的 BOOL 设置为 YES
,如果 aCellIsSelected 为 NO,则重新加载表格视图
Set a BOOL like aCellIsSelected to YES when you touch the cell
and just reload tableview if aCellIsSelected is NO