i trying create calendar view same ios 4 years.
the hierarchy like: uicollectionview: 1 section each year uicollectionviewcell: 12 cells/items 12 months in year uicollectionview: uicollectionviewcell: upto 31 cells month day string, have uilabel content.
screenshot attached.
in order on laggy scrolling, removed datasource of month cells. container view controller data source both collectionviews.
the 12 month collection view has been subclassed store index path year value. got trick tutorial: https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell/
but issue still there calling reloaddata on month cell before displaying it.
to fix did override prepareforreuse() method of uicollectionviewcell , set indexpath, delegate , datasource properties nil in monthcollectionviewcell. also, removed reloaddata call. scrolling still laggy.
the tutorial link pretty same workflow.
here link code: https://github.com/nipun0505/testcalendarview
you can reduce lag by:
1) caching colors.
try commenting out line of code , see how better lag is:
// if ([[_datecompareformatter stringfromdate:date] isequaltostring:[_datecompareformatter stringfromdate:[nsdate date]]]) // { // daycell.daylabel.backgroundcolor = [uicolor cyancolor]; // } // else // { // daycell.daylabel.backgroundcolor = [uicolor clearcolor]; // }
after caching colors, keep in mind clear colors, lag more opaque colors.
2) why creating date formatter on , on again in function?
(uicollectionreusableview *)collectionview:(uicollectionview *)collectionview viewforsupplementaryelementofkind:(nsstring *)kind atindexpath:(nsindexpath *)indexpath nsdateformatter *df = [[nsdateformatter alloc] init];
please cache stuff this. caching friend.
3) performance can increased in other areas. calendar load time horrible :s .
if speed up, , above 2 things, see noticeable increase in speed.
[edit #3] --> mean im saying load time calendar 4 seconds. because displaying many items on screen. maybe can change design bit? here's crazy idea. every month, calendar has keep track of around 30 items. that's 30 items per month 15 months per iphone 6s screen. instead of keeping track of 30 items, maybe keep track of 6 labels arranged in row of monthcell? have use calculation text aligned, performance boost incredible if can work.
i see having blue colored view. can have 2 types of cells. 1 6 labels, , 30 items. can present cell based on needs. there many things can cook-up increase performance.
Comments
Post a Comment