ios - How to set custom background color of UITableViewCell even there's no data inside -
i want accomplish :
see there's 1 data but, background color continue until end.
i understand can inside tableview delegate of tableview:willdisplaycell:forrowatindexpath:
. doesn't go empty cell, hence empty cell white.
i used following code display cell alternative color if cell not initialized.i have done work on scrollviewdidscroll showing below:--
- (void)scrollviewdidscroll:(uiscrollview *)scrollview { uiview *view=[[uiview alloc] initwithframe:tblview.frame]; view.backgroundcolor=[uicolor greencolor]; uiview *cellview; int y=0; int i=0; (uiview *view in tblview.subviews) { if ([nsstringfromclass([view class]) isequaltostring:@"_uitableviewseparatorview"]) { cellview=[[uiview alloc] initwithframe:cgrectmake(0, y, 320, 44)]; if (i%2==0) { cellview.backgroundcolor=[uicolor redcolor]; }else{ cellview.backgroundcolor=[uicolor greencolor]; } [view addsubview:cellview]; i++; } } tblview.backgroundview=view; }
and got correct result on scrolling table view. problem works when user scrolls tableview atleast once time. if success fire event on tableview completes reloading.then fine.
here output got on scrolling tableview.
i write method call didscrollmethod manually doesn't seems work perfectly.
[tblview.delegate scrollviewdidscroll:(uiscrollview*)tblview.superclass];
but calling method code below absolutely works fine.
- (void)viewdidload { tblview=[[myfirstview alloc] init]; tblview.delegate=self; [tblview setframe:self.view.frame]; [self.view addsubview:tblview]; [super viewdidload]; // additional setup after loading view, typically nib. } -(void)viewdidappear:(bool)animated{ [tblview.delegate scrollviewdidscroll:(uiscrollview*)tblview.superclass]; }
means after loading tableview in viewdidload call didscroll in viewdidappear works fine.
insert below code if fluctuates first row while scrolling.
- (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section { uiview *view=[[uiview alloc] init]; return view; }
Comments
Post a Comment