简体   繁体   中英

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. 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. 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. 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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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