Friday, 15 August 2014

ios - UITableview getting custom cell height -



ios - UITableview getting custom cell height -

im develop custom cell in tableview using method:

http://www.appcoda.com/ios-programming-customize-uitableview-storyboard/

my concern before start following.

the cell contain 3 labels, in cases short labels, in cases long labels.

the effect has height of cell alter considerably.

is there anyway can height of cell of

- (cgfloat) tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath{

call

or there improve method of i'm trying do.

thanks

the improve method calculate height before rendering view.

for illustration got 3 labels next data:

title subtitle description

what calculate size of each string by:

uifont *yourfont = // [uifont ...] cgsize stringboundingbox = [somestring sizewithfont:yourfont];

i store size in stack of info key of corresponding info (title, subtitle, description), keys

titlesize //for title subtitlesize //for subtitle descriptionsize

the item of nsarray like:

@{ @"titlesize" : [nsvalue valuewithcgsize:(cgsize)titlesize], @"subtitlesize" : [nsvalue valuewithcgsize:(cgsize)subtitlesize], @"descriptionsize" : [nsvalue valuewithcgsize:(cgsize)descriptionsize], @"title" : title, //the nsstring info @"subtitle" : subtitle, //the nsstring info @"descriptionsize" : descriptionsize, //the nsstring info }

and in here can have:

- (cgfloat) tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath{ nsdictionary *item = stack[indexpath.row]; cgsize titlesize = [item[@"titlesize"] cgsizevalue]; cgsize subtitlesize = [item[@"subtitlesize"] cgsizevalue]; cgsize descriptionsize = [item[@"descriptionsize"] cgsizevalue]; //calculate right height , stuff. ........... homecoming height; }

you can create constants or methods margins , paddings having.

the beauty of solution calculating once. if info updates given item, need recalculate sizes , reload tableview.

ios objective-c xcode

No comments:

Post a Comment