테이블 뷰 셀의 동적 높이의 경우이 링크에서 참조를 가져옵니다.동적 셀 높이가있는 UITableview의 AutoLayout
내 문제는 내가 오류를 얻을 수 있습니다 : 여기
Using Auto Layout in UITableView for dynamic cell layouts & variable row heights
는
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; { return arrTemp. count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *[email protected]"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; }
나는이 개 질문이있는 tableview 데이터 소스 및 위임 방법의 내 코드입니다
EXE_BAD_EXCESS
라인 근처AutoLayoutTableViewCell *cell = (AutoLayoutTableViewCell *)[IBtblAutoLayoutExample cellForRowAtIndexPath:indexPath];
heightForRowAtIndexPath
및estimatedHeightForRowAtIndexPath
입니다.cellForRowAtIndexPath
과heightForRowAtIndexPath
에 모두 라벨 텍스트를 써야하는 이유는 무엇입니까?
또한 동적 높이를 얻는 데 필요한 것이 누락 되었습니까?
IBtblAutoLayoutExample은 테이블 뷰의 이름입니까? – EridB
예, 내 tableview에 IBOutlet입니다. –
heightForRowAtIndexPath 및 estimatedHeightForRowAtIndexPath를 구현할 필요가 없다고 생각합니다. 이는 셀의 직접 제약 조건으로 가능할 수 있으며 테이블 뷰의 행 및 행 높이 추정치 속성을 설정하기 만하면됩니다. –