1. First, set some attributes of the container (which is assumed to be a label) that displays text in the cell, as shown below:
[_ Labelsetnumberoflines: 0]; // set the number of lines of text in the label. 0 indicates adaptive
[_ Labelsetlinebreakmode: nslinebreakbywordwrapping]; // Line Disconnection Mode
[_ Labelsetfont: [uifontsystemfontofsize: 16.0]; // font size
2. In the cell's-(void) layoutsubviews method, reset the label height in the cell (calculate the height based on the adaptive line feed)
Nsstring * text = [_ array objectatindex: indexpath. Row];
Cell. Label. Text = text; // obtain the corresponding data from the data source
Nsdictionary * DIC = [nsdictionarydictionarywithobject: [uifontsystemfontofsize: 16.0] forkey: nsfontattributename]; // The font size here must be the same as the label font size you set.
Cgsize textsize = [textsizewithattributes: DIC]; // calculate the size based on the data in the dictionary.
Cgrect rect = _ label. frame;
Rect. Size. Height = textsize. height;
_ Label. Frame = rect;
3. Finally, modify the cell Row Height and calculate it again in the Protocol method for setting the cell Row Height.
Nsstring * text = [_ array objectatindex: indexpath. Row];
Cell. Label. Text = text; // obtain the corresponding data from the data source
Nsdictionary * DIC = [nsdictionarydictionarywithobject: [uifontsystemfontofsize: 16.0] forkey: nsfontattributename]; // The font size here must be the same as the label font size you set.
Cgsize textsize = [textsizewithattributes: DIC]; // calculate the size based on the data in the dictionary.
Return textsize. height;