为什么不应该在删除/插入行的方法上调用reloadData [英] why reloadData shouldn't be called on methods that delete/insert rows

查看:45
本文介绍了为什么不应该在删除/插入行的方法上调用reloadData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现麻雀,例如显示操作行的行滑动(我的开始重点是代码).

I was trying to implement sparrow like row swiping that shows an action row (My starting point was this code).

为我创建的每一行..我还创建了一个引用父行的'backView'UITableViewCell ..这样,当我在backView上单击删除"时..它知道要删除的电子邮件等.

for each row I create.. I also create a 'backView' UITableViewCell that references the parent row.. so that when I click delete on the backView for example.. it knows which email to delete etc.

而不是使用iOS的内置编辑模式删除..我只是在backView上创建了一个按钮,并为其添加了事件处理程序.父单元格是后视图的委托.后视图将删除任务交给父单元.

Instead of using iOS's built in editing mode delete.. I just created a button on the backView and attached an event handler to it. the parent cell is the delegate of the back view.. and the back view hands off the delete task to the parent cell.

我遵循了苹果的指令不要在我的事件处理程序方法中添加reloadData.但是后来一切都搞砸了..我要删除一行,它不会被删除或以错误的顺序被删除等等.我注意到,如果我每次删除后都跳回到父菜单.完美地运作了.因此使用可以解决所有问题(即强行将reloadData放入其中).

I followed apple's instruction not to add reloadData in my event handler method. But then things got all messed up.. i'd delete a row and it wouldn't get deleted or gets deleted in the wrong order etc.. I noticed that if i just jumped back to the parent menu after each delete.. things worked perfectly.. and so using this work around (ie brute forcing reloadData in) everything worked perfectly.

我的问题是(很长的介绍很抱歉)为什么我们要求不要在插入/删除方法中使用reloadData?还是仅当我们使用编辑模式删除行的方式?苹果对此不太清楚.

My question is (sorry for the long introduction) why are we asked not to use reloadData in insertion/deletion methods? Or is this instruction applicable only when we use the editing mode way of deleting rows? Apple is not quite clear about it.

推荐答案

由于-[UITableView reloadData] 重新加载了所有数据,因此基本上使对UI的任何临时的,非永久的更改都无效.您应该在数据结构中反映这些更改,或者,我认为通常这是一个更好的主意,请坚持使用Apple的默认方法(尝试仅更改图形,而不更改逻辑).

Since - [UITableView reloadData] reloads all the data, it basically invalidates any temporary, non-permanent changes to the UI. You should either reflect these changes in your data structure, or, and I think it's generally a better idea, stick to Apple's default methods (try changing the graphics only, not the logic).

这篇关于为什么不应该在删除/插入行的方法上调用reloadData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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