Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apps crashes while reload collectionview in UITableViewCell

I am developing one iOS app with Swift 2.3 .My View controller (ABC) contains UITableView and all data will be binded on controller level . I have prepared custom Tableview Cell which contains collection view with horizontal scrolling of dynamic images . After preparing all data i will reload collection view from ViewController to bind images . All images are downloaded from server using SDWebCahche image library. All works fine if scrolls slowly . My issue raised while i try to scroll fast . Below i see only one crash in console .

libc++abi.dylib: terminating with uncaught exception of type NSException

Also see attached image thread status after crash.

enter image description here

enter image description here

Thanks in Advance .

like image 540
VDPATEL Avatar asked Jun 05 '26 01:06

VDPATEL


1 Answers

I have solved this issue by adding below code in my Custom UITableViewCell.

I have added UITableviewcell method "prepareForReuse". In this method i have cleared all my CollectionView related data and reload collectionview.

e.g

override func prepareForReuse {
  arrImges.removeAll()
  collectionView.reloadData()
}

as i have noticed this method is invoked when my UITableViewCell start deque. So all my collectiobView data will be cleared and new data will be reloaded again while preparing data new data in My Controller.

like image 73
VDPATEL Avatar answered Jun 07 '26 23:06

VDPATEL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!