In the cell.m file
1) Initialize the method:
Self.lalname=[[uilabel Alloc] Initwithframe:cgrectmake (5, +)]; [Self addSubview:self.lalName];
2) Create a method:
Introduce the assignment to the user and implement the wrap-(void) Setintroductiontext: (nsstring*) text{ //Get the height of the current cell cgrect frame=[self frame]; Text assignment value self.lalname.text=text; Cgsize Size=cgsizemake (+); Sets the maximum number of rows for a label self.lalname.numberoflines=10; Cgsize labelsize=[self.lalname.text sizeWithFont:self.lalName.font constrainedtosize:size linebreakmode: Nslinebreakbyclipping]; Self.lalname.frame=cgrectmake (self.lalname.frame.origin.x, SELF.LALNAME.FRAME.ORIGIN.Y, LabelSize.width, Labelsize.height); Calculate the height of frame.size.height=labelsize.height+20 from adaptation ; Self.frame =frame; }
In the Viewcontroller:
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{ static NSString *[email protected] "Acell"; Textkittableviewcell *cell=[tableview Dequeuereusablecellwithidentifier:acell]; if (!cell) { cell=[[[nsbundle mainbundle] loadnibnamed:@ "Textkittableviewcell" Owner:self options:nil]lastObject ]; } [Cell setintroductiontext:@] where is you? Where is you? Where is you? Where is you? wher E is you? Where is you? Where is you? Where is You?where is you? Where is you? Where is you? Where is you? Where is you? Where is you? Where is you? Where is you? Where is you? Where is you? "]; return cell; }
Of course, don't forget to return to cell height
-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{ UITableViewCell *cell=[self tableView:self.tableViewTextKit Cellforrowatindexpath:indexpath]; NSLog (@ "height===%f", cell.frame.size.height); return cell.frame.size.height;}
IOS UITableViewCell Adaptive Height