ios - Change height of cell with change frame of content -
i can make animating of changing row height bad uitableviewrowanimationfade, because it's flickers when animate
- (void)viewdidload { [super viewdidload]; self.title = @"main vc"; selectedindexes = [nsmutabledictionary new]; } - (void)willanimaterotationtointerfaceorientation:(uiinterfaceorientation)tointerfaceorientation duration:(nstimeinterval)duration { [self.tableview reloaddata]; } - (bool)cellisselected:(nsindexpath *)indexpath { nsnumber *selectedindex = [selectedindexes objectforkey:indexpath]; return selectedindex == nil ? no : [selectedindex boolvalue]; } - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { static bool nofirst; if (!indexpath.row && !nofirst) { [selectedindexes setobject:@(yes) forkey:indexpath]; nofirst = yes; } if ([self cellisselected:indexpath]) { uiimage *cellimage = helperdf.dataarray[indexpath.row][@"image"]; cgfloat aspectratioindex = cellimage.size.height / cellimage.size.width; return [utils screenwidth:self.interfaceorientation] * aspectratioindex; } else { return heightcell; } }
my didselectrowatindexpath
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { nsmutableset *insideset = [nsmutableset new]; [insideset addobject:indexpath]; bool isselected = ![self cellisselected:indexpath]; (nsindexpath *keyindexpath in selectedindexes) { [insideset addobject:keyindexpath]; } [selectedindexes removeallobjects]; [selectedindexes setobject:@(isselected) forkey:indexpath]; [tableview reloadrowsatindexpaths:insideset.allobjects withrowanimation:uitableviewrowanimationnone]; }
so if use [tableview beginupdates] [tableview endupdates
problems change frame of labels , numberoflinew
. how can change frames of labels , other parametres, change in cellforrowatindexpath
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"maincell"; maincell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; nsdictionary *datadictionary = helperdf.dataarray[indexpath.row]; cell.titlelabel.text = datadictionary[@"title"]; cell.descriptionlabel.width = [utils screenwidth:self.interfaceorientation] - 40; cell.descriptionlabel.text = datadictionary[@"fulltext"]; if ([self cellisselected:indexpath]) { cell.sequebtn.hidden = no; cell.pictureview.contentmode = uiviewcontentmodescaletofill; cell.descriptionlabel.numberoflines = 7; } else { cell.sequebtn.hidden = yes; cell.pictureview.contentmode = uiviewcontentmodescaleaspectfill; cell.descriptionlabel.numberoflines = 2; } [cell.descriptionlabel sizetofit]; cell.pictureview.image = datadictionary[@"image"]; return cell; } - (void)tableview:(uitableview *)tableview willdisplaycell:(uitableviewcell *)cell forrowatindexpath:(nsindexpath *)indexpath { maincell *maincell = (maincell *)cell; maincell.descriptionlabel.originy = maincell.sequebtn.hidden ? heightcell - maincell.descriptionlabel.height - 5 : maincell.height - maincell.sequebtn.height - maincell.descriptionlabel.height - 12; }
this code used set uitableviewcell height dynamically:
- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { nsdictionary* dict = [branchesarray objectatindex:indexpath.row]; nsstring* address = [nsstring stringwithformat:@"%@,%@\n%@\n%@\n%@",[dict objectforkey:@"locality"],[dict objectforkey:@"city"],[dict objectforkey:@"address"],[dict objectforkey:@"contactnumber"], [dict objectforkey:@"contactemail"]]; cgsize constraint = cgsizemake(220, maxfloat); cgsize size = [address sizewithfont:[uifont fontwithname:@"helvetica" size:14.0f] constrainedtosize:constraint linebreakmode:nslinebreakbywordwrapping]; cgfloat height1 = max(size.height, 110.0f); return height1+20; }
as set frame in - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath
also
Comments
Post a Comment