I found several posts already about SO regarding UICollectionView scrolling, but most of them related to images, and my situation was slightly different and simpler.
I have a uicollectionview that shows the current year, last year, and next year (so 36 sections, with x the number of days per section). All of this is sorted by load of browsing and pretty fast as I did.
However, the problem is that the initial scroll, which takes place in the uicollectionview window, has a very small but noticeable lag, and then all this oil.
func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell!
{
let day = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CalendarDayCollectionViewCell
So, you can see here, I have a custom cell, and I am accessing it as shown above. If I am in the current month, then the above is called 31 times (or how many days in this month).
Even if I comment on EVERYTHING in the code above (and just “day” as it is, without another code below), it is still lagging.
Other things I've tried:
- Wrap everything I can in dispatch_async
- Removing almost all bits of code to launch a skeleton page. It still has an initial lag, it is almost as if the sheer number of sections / elements is a problem.
So, one thing that I read is that I cause the cell to reload every time and create an initial delay?
let day = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CalendarDayCollectionViewCell
Someone wrote that you need to make this singleton and stop reinstalling it, as well as access the same thing over and over again. It's true? I have not seen any code that actually did this. I tried something like this:
if (day == nil)
{
day = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CalendarDayCollectionViewCell
}
nil, .
- ?
, , ", , , - .." , , , , 1/4 , .
, ( , ).
/?
!