ios - UITableView loading section before particular section -
i trying show calendar
uitableview
. each section corresponds each year of calendar , every section contains 12 cells correspond 12 months.
i trying show 10 years calendar, 5 years current date , 5 coming years. can load current year(section) 2013 section 0 in uitableview
. when scroll table upward want see year 2012 above year 2013. 2013 section 0 cant though can insert new sections after current section simple.
- (id)initwithframe:(cgrect)frame logic:(linekalmonthlogic *)thelogic delegate:(id<linekalviewdelegate>)thedelegate { frame.size.width = kklinetilesize.width; frame.size.height = 31 * kklinetilesize.height; if (self = [super initwithframe:frame]) { self.clipstobounds = yes; logic = [thelogic retain]; delegate = thedelegate; cgrect rect = cgrectmake(0, 0,1024, 716); _maintable =[[uitableview alloc] initwithframe:rect style:uitableviewstylegrouped]; _maintable.delegate = self; _maintable.datasource = self; _maintable.backgroundcolor = [uicolor graycolor]; [self addsubview:_maintable]; monthheight = 723; backmontharray = [[nsmutablearray alloc] init]; heightarray = [[nsmutablearray alloc] init]; _sectionno = 1; } return self; } -(void)calculatemonths:(int)monthno{ int ; (i=monthno; i<monthno+12; i++) { cgrect monthrect = cgrectmake(0.f, 0.f, 1024,723); backmonthview = [[[linekalmonthview alloc] initwithframe:monthrect anddays: [logic numberofdaysinmonth:i] andmonthname:(nsstring *)[logic gettingmonthdate:i]] autorelease]; [delegate showforcurrentmonth]; [backmonthview showdates:logic.daysinselectedmonth leadingadjacentdates:logic.daysinfinalweekofpreviousmonth trailingadjacentdates:logic.daysinfirstweekoffollowingmonth]; [backmontharray addobject:backmonthview]; [delegate reloaddata]; monthheight = backmonthview.frame.size.height; [heightarray addobject:[nsnumber numberwithfloat:monthheight]]; } nextmonthno = i;
}
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return _sectionno; //count of section } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return 12; } - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { return [[heightarray objectatindex:indexpath.row+indexpath.section*12] intvalue]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *myidentifier = @"myidentifier"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:nil]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:myidentifier] autorelease]; cell.selectionstyle = uitableviewcellselectionstylenone; } [cell.contentview addsubview:[backmontharray objectatindex:indexpath.row+indexpath.section*12]]; //backmontharray contains 12 months data return cell; } -(void)tableview:(uitableview *)tableview willdisplaycell:(uitableviewcell *) cell forrowatindexpath:(nsindexpath *)indexpath { if(indexpath.row == 10 && indexpath.section == _sectionno-1) //self.array array of items displaying { dispatch_async(dispatch_get_main_queue(), ^{ [self calculatemonths:nextmonthno]; _sectionno = _sectionno+1; [_maintable insertsections:[nsindexset indexsetwithindex:_sectionno-1] withrowanimation:uitableviewrowanimationnone]; }); } }
so want show sections before current section.
Comments
Post a Comment