AutoLayout in UITableview mit dynamischer Zellenhöhe

Bezüglich der dynamischen Höhe meiner Tabellenzelle verweise ich auf diesen Link.Verwenden des automatischen Layouts in UITableView für dynamische Zellenlayouts und variable Zeilenhöhen

Hier ist mein Code für die Tabellenansicht-Datenquelle und die Delegierungsmethoden

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
  {
       return arrTemp. count;
  }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier=@"AutoLAyoutCell";

AutoLayoutTableViewCell *cell=(AutoLayoutTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
    for (id currentObject in [[NSBundle mainBundle] loadNibNamed:@"AutoLayoutTableViewCell" owner:self options:nil]) {
        if ([currentObject isKindOfClass:[UITableViewCell class]]) {
            cell = (AutoLayoutTableViewCell *)currentObject;
            break;
        }
    }
}

cell.IBlblLineNo.text=[NSString stringWithFormat:@"Line:%i",indexPath.row];
cell.IBlblLineText.text=[arrTemp objectAtIndex:indexPath.row];
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];

CGSize expectedlineLabelSize = [cell.IBlblLineText.text sizeWithFont:cell.IBlblLineText.font constrainedToSize:CGSizeMake(280, 1000) lineBreakMode:NSLineBreakByTruncatingTail];
cell.IBlblLineText.numberOfLines=expectedlineLabelSize.height/17;

CGRect frmlbl=cell.IBlblLineText.frame;
frmlbl.size.height=expectedlineLabelSize.height;
cell.IBlblLineText.frame=frmlbl;

return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

AutoLayoutTableViewCell *cell = (AutoLayoutTableViewCell *)[IBtblAutoLayoutExample cellForRowAtIndexPath:indexPath];

cell.IBlblLineNo.text=[NSString stringWithFormat:@"Line:%i",indexPath.row];
cell.IBlblLineText.text=[arrTemp objectAtIndex:indexPath.row];

[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];

CGSize expectedlineLabelSize = [cell.lineLabel.text sizeWithFont:cell.lineLabel.font constrainedToSize:CGSizeMake(280, 1000) lineBreakMode:NSLineBreakByWordWrapping];

 cell.IBlblLineText.numberOfLines=expectedlineLabelSize.height/17;
CGRect frmlbl=cell.IBlblLineText.frame;
frmlbl.size.height=expectedlineLabelSize.height;
cell.IBlblLineText.frame=frmlbl;

CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
height += 1.0f;

return height;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
     AutoLayoutTableViewCell *cell = (AutoLayoutTableViewCell *)[IBtblAutoLayoutExample cellForRowAtIndexPath:indexPath];

 CGSize expectedlineLabelSize = [cell.IBlblLineText.text sizeWithFont:cell.IBlblLineText.font constrainedToSize:CGSizeMake(280, 1000) lineBreakMode:NSLineBreakByTruncatingTail];

 return expectedlineLabelSize.height;

}

Ich habe 2 Fragen:

Mein Problem ist, dass ich den Fehler erhalteEXE_BAD_EXCESS in der Nähe der Linie

AutoLayoutTableViewCell *cell = (AutoLayoutTableViewCell *)[IBtblAutoLayoutExample cellForRowAtIndexPath:indexPath]; 

imheightForRowAtIndexPath undestimatedHeightForRowAtIndexPath.

Warum muss ich in beiden einen Beschriftungstext schreiben?cellForRowAtIndexPath undheightForRowAtIndexPath?

Fehlt mir auch etwas, um eine dynamische Höhe für die Zelle zu erreichen?

Antworten auf die Frage(1)

Ihre Antwort auf die Frage