简体   繁体   English

UITableView由于在滚动tableview的同时重新加载数据而崩溃

[英]UITableView is crashing due to reload data at the same time as scrolling the tableview

I am using UITableView to show a list of records. 我正在使用UITableView显示记录列表。 My table allows refresh from top and bottom. 我的表格允许从顶部和底部刷新。 On refreshing from top, the old records remain visible until new data is fetched. 从顶部刷新后,旧记录将保持可见,直到获取新数据为止。 After the data is fetched, all the records from the array are removed and new records are filled. 提取数据后,将删除数组中的所有记录,并填充新记录。 Then as a final step I refresh the tableview to reflect the newly fetched data. 然后,作为最后一步,我刷新表视图以反映新获取的数据。

All works like a charm. 所有的作品都像魅力。

BUT... 但...

Its causing a crash when we do monkey testing. 当我们进行猴子测试时,它会导致崩溃。 During the top refresh, when the data is being fetched, if I keep scrolling, pulling the tableview, after several attempts there comes an unlucky moment when array is being removed to add the new records but at that time UITableView is also laying out the cells due to constant pulling. 在最高级刷新期间,如果正在获取数据,则如果我继续滚动并拉动tableview,则经过几次尝试之后,不幸的是删除了数组以添加新记录时,但那时UITableView还在布置单元格由于不断拉。 This causes the crash. 这会导致崩溃。

An easy fix would be to empty the tableview when doing a top refresh but that don't look good as far as the ui aesthetic is concerned. 一个简单的解决方法是在进行顶部刷新时清空tableview,但是就ui美学而言,这看起来并不好。 Also if the call fails I won't have anything to show to the user. 另外,如果通话失败,我也不会向用户显示任何内容。

I tried by encapsulating the refreshing code in tableview's beginUpdate and endUpdate block but that won't run as there is no change in the tableview itself (ie no adding/deleting). 我尝试通过将刷新代码封装在tableview的beginUpdateendUpdate块中进行beginUpdate ,但是由于tableview本身没有更改(即没有添加/删除),因此无法运行。

Any help would be appreciated. 任何帮助,将不胜感激。

Since you say you scroll away and crashes is probably because you try to insert data to indexes that are no longer visible. 既然您说滚动离开并崩溃了,可能是因为您试图将数据插入不再可见的索引中。 You should somehow check at what index you are before trying to update the table. 在尝试更新表之前,您应该以某种方式检查您正在使用的索引。 Some code would help me better understand. 一些代码可以帮助我更好地理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM