Reputation: 1935
OK, I am implementing a calendar that pretty much looks like Apple's Calendar app.
I have many types of cells in my UICollectionView
.
I have cells for vertical lines, cells for horizontal lines, a cell for now line, and for events.
Whenever I scroll, and a cell appears for the first time, there is a little glitch, lag, delay, name it however.
As a POC, I created this test case: Create 2 days. One has 5 events from 00:00 to 05:00, and 5 events from 17:00 to 22:00. The second day has only 5 events from 17:00 to 22:00. The first day, which has also the morning events, doesn't lag when scrolling to the 17:00-22:00 events. The second one DOES.
PLUS, there is no lag at all in the line cells, as they are presented in every frame of the collectionView.
This leads me to the question - I want to have the cells deque'd before scrolling - so I know that cells that are NOT in the screen (but will be once the users scrolls) are deque'd in an amount that will be efficient for the collectionView to reuse them once the user scrolls.
Naive approach which I am not sure about will be something like this:
in ViewDidLoad()
to run something like this:
(0...10).forEach { num in
calendarCollectionView.dequeueReusableCell(withReuseIdentifier: "UserEventCollectionViewCell", for: IndexPath(item: num, section: 3)) //3 is my events section
}
this leads to a crash:
Thread 1: EXC_BAD_ACCESS (code=1, address=0xae106)
How can I achieve this? Or is there any better approach?
Some screenies:
In the screen shots - the area with the lines and hours is a contained VC, which is the relevant for the question (under the label "monday, ...")
Upvotes: 3
Views: 111
Reputation: 1935
OK - this is pretty crazy. We found that the reason for our lags was solely the fact that we had too many print outs to the console. We removed them and everything is smooth now. This is not a direct answer to my question, but it makes me understand - when you think you need to pre load nib files to boost smoothness - something else in your implementation is the reason for the lags and you should find it instead of hacking through it.
Upvotes: 1