objective c - NSTextField dynimic height in NSTableView -
there nstextfield in nstableview.
the height of text in window resizing increased. not grow cells in table view.
in case, height of table view cell alter how like?
in short, when resizing size of text view, want change size of cell.
like this: (mac store)
- (cgfloat)tableview:(nstableview *)tableview heightofrow:(nsinteger)row; { kfcustomcellview *cellview = [tableview makeviewwithidentifier:@"maincell" owner:self]; nsstring *comment = [[_commentlist objectatindex:row]valueforkey:@"comment"]; [cellview.comment setstringvalue:comment]; float cellheight = [comment heightforstringdrawing:comment font:[cellview.comment font] width:self.view.frame.size.width * 0.8]; if (cellheight > cellview.comment.frame.size.height) { return (cellheight + 65); } return 90; }
use following approach resize cell height according textview content :
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *datacellid = @"datacell"; datacell = (cell *)[tableview dequeuereusablecellwithidentifier:datacellid]; if(!datacell) { datacell = [[[cell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:datacellid] autorelease]; } datacell.datacelltextview.tag = indexpath.row; datacell.datacelltextview.text =[yourdataarry objectatindex:indexpath.row]; return datacell; } - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { #define paddingfortablerowheight 24 nsstring *text; if([yourdataarry count] > indexpath.row) { text = [yourdataarry objectatindex:indexpath.row]; } else { text = @""; } uifont *datafont = [uifont boldsystemfontofsize:16.0f]; cgsize textsize ; if([uicommonutils checkifios7]) { // ios7 textsize = [text boundingrectwithsize:cgsizemake("your cell width", maxfloat) options:nsstringdrawinguseslinefragmentorigin attributes:@{nsfontattributename:datafont} context:nil].size; } else { textsize = [text sizewithfont:datafont constrainedtosize:cgsizemake("your cell width" - paddingfortablerowheight,maxfloat)]; } float textviewheight = max(kdefaultcellheight, textsize.height+paddingfortablerowheight); return textviewheight; } -(void)textviewdidbeginediting:(uitextview *)textview { [self scrolltocursorfortextview:textview]; } -(void)textviewdidendediting:(uitextview *)textview { if([yourdataarry count] > textview.tag) { [yourdataarry replaceobjectatindex:textview.tag withobject:textview.text]; } } - (void)textviewdidchange:(uitextview *)textview { dataupdated =yes; if([yourdataarry count] > textview.tag) { [yourdataarry replaceobjectatindex:textview.tag withobject:textview.text]; } [self performselector:@selector(datareload) withobject:nil afterdelay:0.0]; [self scrolltocursorfortextview:textview]; } -(void)datareload { [self.tbl beginupdates]; [self.tbl endupdates]; }
Comments
Post a Comment