When the content of a label in the UITableView is longer, it is necessary for the cell to adapt to the height to display the label in multiple lines;
First set the label line to 0;
The code is as follows:
//Pre-set a height for each cell to increase efficiency-(CGFloat) TableView: (UITableView *) TableView Estimatedheightforrowatindexpath: (Nsindexpath *) Indexpath {return -;}//the actual height of each cell here (ie, adaptive height)-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath {//you can set the adaptive height individually for the line you need by using the IF Judgment statement. if(Indexpath.row = = [Rowsarr count]-1) { //the height required to get the label through the dataNSString *rowname =[Rowsarr ObjectAtIndex:indexPath.row]; NSString*key =[Rowsandkeydic Objectforkey:rowname]; CGFloat Descriptionh=[self textheight:[taskdetaildic objectforkey:key]]; returnDescriptionh + -;//This 70 is completely tuned to your situation . } return -;}//Gets the height that the label actually needs-(CGFloat) TextHeight: (NSString *) LabelText {Uifont*tfont = [Uifont systemfontofsize:16.0]; Nsdictionary* dic =[Nsdictionary Dictionarywithobjectsandkeys:tfont,nsfontattributename,nil]; //iOS7 API to determine the height of labelText this string, the width here (self.view.frame.size.width-140he) as needed to change the OKCgsize Sizetext = [LabelText boundingrectwithsize:cgsizemake (Self.view.frame.size.width- $, +) Options:nsstringdrawinguseslinefragmentorigin Attributes:dic context:nil].size; returnsizetext.height;}
IOS Controls-cell adaptive height in UITableView