UILable 문자열의 길이에 따라 높이 (사용자 지정 UITableViewCell 높이)가 결정되는 행을 삽입해야하는 UITableView를 디자인하려고합니다.insertRowAtIndexPath가있는 동적 UITableViewCell
다음은 Ray Wenderlich의 this tutorial에이어서 UILabel 높이에 대한 셀의 높이를 조정할 수 있습니다. 내가, 사용자 정의있는 UITableViewCell을 사용하여 행을 삽입 insertRowAtIndexPath를 사용할 때
dispatch_once(&onceToken, ^{
sizingCell = [self.tableView dequeueReusableCellWithIdentifier:RWBasicCellIdentifier];
});
은 행이 여러 번 한 번만 삽입되지는 않습니다 있는지 확인합니다.
가변 높이의 RowAtIndexPath를 삽입하는 방법은 무엇입니까?
여기에 당신은 또한 테이블 뷰 컨트롤러에 heightForRowAtIndexPath
를 구현해야 내 heightForRowAtIndexPath
ChattingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChattingCellId2"];
CGRect messageLabelRect = [cell.labelMessage.attributedText boundingRectWithSize:(CGSize){cell.labelMessage.frame.size.width, CGFLOAT_MAX} options:NSStringDrawingUsesLineFragmentOrigin context:nil];
cell.labelMessage.frame = CGRectMake(cell.labelMessage.frame.origin.x, cell.labelMessage.frame.origin.y, cell.labelMessage.frame.size.width, messageLabelRect.size.height);
[cell.labelMessage sizeThatFits:CGSizeMake(cell.labelMessage.frame.size.width, messageLabelRect.size.height)];
float height = cell.labelMessage.frame.origin.y + cell.labelMessage.frame.size.height + cell.labelSent.frame.size.height + 10;
[cell prepareForReuse]; //here your cell would normally be returned for cellForRowAtIndexPath, except we just mark it for reuse, we have the height we need
return height;
게시 된 코드는 귀하의 질문과 어떤 관련이 있습니까? 'insertRowAtIndexPath'를 사용하는 것은 당신의 질문과 무관합니다. 'heightForRowAtIndexPath'를 구현하십시오. 테이블에 추가되는 방법에 관계없이 모든 행을 처리합니다. – rmaddy
나는 @rmaddy를 이해하고있다 .. 나는 데이터 소스와 델리게이트 메소드를 알고있다. 그러나 heightForRowAtIndexPath를 사용하여 하나의 셀에 대해서만 UITableViewHeight를 어떻게 변경 하는가? –
나는 uitableviewcell 높이를 의미합니다 –