ios - Table view cell only masks correctly after scrolling off and then back on -


i'm modifying table view cell during call tableview:cellforindexpath, modifications not appear until cell scrolled off , on. realize can modify .xib file or can alloc/init cell rather calling dequeue, i'd understand going on.

the changes involve masking cell achieve rounded bottom corners. if set corner radius instead (i.e. cell.layer.cornerradius = ...), rounds corners, don't see problem.

update:

i didn't post code because proprietary, involved lot of complexity , thought question reasonable 1 in absence of specifics. in light of responses, though, here reduced fragment exhibits problem, change being actual cell identifier. updated description/question simplify scenario.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"thecorrectcellidentifier" forindexpath:indexpath];     uibezierpath *maskpath = [uibezierpath bezierpathwithroundedrect:cell.bounds byroundingcorners:uirectcornerbottomleft | uirectcornerbottomright                                                         cornerradii:cgsizemake(4., 4.)];     cashapelayer *masklayer = [cashapelayer layer];     masklayer.frame = cell.bounds;     masklayer.path = maskpath.cgpath;     cell.layer.maskstobounds = yes;     cell.layer.mask = masklayer;     return cell; } 

your code working fine . if still facing corner radius issue in cellforrowatindexpath: try in willdisplaycell: . tried in both methods , working fine.

willdisplaycell:

tells delegate table view draw cell particular row.

table view sends message delegate before uses cell draw row, thereby permitting delegate customize cell object before displayed. method gives delegate chance override state-based properties set earlier table view, such selection , background color. after delegate returns, table view sets alpha , frame properties, , when animating rows slide in or out. here code.

according me, apple provide 2 different set of methods (protocol) named uitableviewdatasource , uitableviewdelegate manage uitableview.

uitableviewdatasource : data source provides actual data cell fill in details.

uitableviewdelegate : @ other end delegate responsible give information visual layout of tableview , handles user interaction.

so, conclusion datasource deal content(data) of table , delegate deal presentation , interaction of tableview component.

lets come way dealing tableview.

we personal uitableviewdatasource method tableview:cellforrowatindexpath:, method responsible create or reuse valid uitableviewcell proper detailed information each index path.what tend cell layout configuration , ui modification in method.

after tableview:cellforrowatindexpath: called, system layout configuration, calls tableview:willdisplaycell:forrowatindexpath: method before cells display on screen.

so can use method view configuration of tableview cell(may be, apple propose method us!!!).

so persionally prefer use tableview:cellforrowatindexpath: create cell , left cell ui configuration task tableview:willdisplaycell:forrowatindexpath: method.

apply mask in willdisplaycell:

 -(void)tableview:(uitableview *)tableview willdisplaycell:(uitableviewcell *)cell forrowatindexpath:(nsindexpath *)indexpath{      uibezierpath *maskpath = [uibezierpath bezierpathwithroundedrect:cell.bounds byroundingcorners:uirectcornerbottomleft | uirectcornerbottomright                                                         cornerradii:cgsizemake(10.0, 10.0)];     cashapelayer *masklayer = [cashapelayer layer];     masklayer.frame = cell.bounds;     masklayer.path = maskpath.cgpath;     cell.layer.maskstobounds = yes;     cell.layer.mask = masklayer;     } 

here cellforrowatindexpath:

-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{  static nsstring *identifier = @"cell";  uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:identifier forindexpath:indexpath];  cell.textlabel.text = [nsstring stringwithformat:@"row : %ld ", (long)indexpath.section]; return cell; } 

output :

enter image description here


Comments