I have a tableView, in each cell there is a collectionView. Sometimes when I know there is new data in collectionViews, I call reloadData()
on collectionView. Most of the time this routine works, but but sometimes is starts to use 100% of CPU, memory usage increasing, GUI is blocked, and at a point app will crash. If I do not let reload collectionView, then all works well, only the content invalid in the collectionView. What is going on, in iOS 8 it was not a problem to call reloadData()
from cellForRowAtIndexPath
.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("movie") as! MovieTableViewCell
//..
if cell.rcvc == nil {
let cvfl = UICollectionViewFlowLayout()
cvfl.scrollDirection = .Horizontal
cell.rcvc = RatingCollectionViewController(collectionViewLayout: cvfl)
self.addChildViewController(cell.rcvc!)
let v = cell.viewWithTag(5)!
v.addSubview(cell.rcvc!.view)
cell.rcvc!.didMoveToParentViewController(self)
cell.rcvc!.view.frame = v.bounds
}
cell.rcvc!.movie = movie
if enableReloadRatingCollectionViews {
cell.rcvc!.collectionView!.reloadData() // <--- if I comment, not crashes
}
return cell
}
I have updated my code like @dasblinkenlight suggest, I am not calling reloadData
anymore from cellforRowAtIndexPath
, but now call reloadData
for all collectionView
s form outside when certain user interaction triggers it. But it still crashes sometimes, any idea why?
itemTableViewController!.tableView.reloadData()
for sv in collectionViews.allObjects {
(sv as! UICollectionView).reloadData()
}
Instead of reloading the nested collectionView
, I implemented a configureCell
method, that reset cell, and for all the visible cell I call configureCell
. That is my fix, and so the infinite loop can avoid.
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.