Interface Builder를 통해 tableViewCell을 tableView에 추가했습니다. 그 중 하나에는 UITextView가 포함되어 있습니다.UITextView의 크기를 변경할 수 없습니다
있는 tableView은 버튼을 클릭 도착으로 다시로드 : 내 cellForRowAtIndexPath 방법에
- (void)updateViewWithMessage:(NSString *)message
{
self.someMessage = message;
[self.tableView reloadData];
}
나는이 셀 확인하고 다음을 수행 : 나는 높이를 계산) heightForContentView에서
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CellIdentifier = kMyCustomCell;
MyCustomCell *contentCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
CGRect textViewFrame = contentCell.contentTextView.frame;
textViewFrame.size.height = [self heightForContentView];
NSLog(@"%f, %f, %f, %f\n", textViewFrame.origin.x,
textViewFrame.origin.y,
textViewFrame.size.width,
textViewFrame.size.height);
contentCell.contentTextView.frame = textViewFrame;
contentCell.contentTextView.text = self.someMessage;
return contentCell;
}
을 (:
- (CGFloat)heightForContentView
{
CGSize boundingRectSize = CGSizeMake(kCustomCellWidth - 20, CGFLOAT_MAX);
CGRect textViewRect = [self.someMessage boundingRectWithSize:boundingRectSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:nil
context:nil];
return textViewRect.size.height + 20;
}
셀 높이 행을 설정하면 제대로 크기를 조정합니다. 그러나 텍스트 뷰는 그렇지 않습니다. 내 버튼을 두 번 클릭하면 (updateViewWithMessage : 메소드가 다시 호출 됨) 크기가 조정됩니다.
그런데 NSLog는 정확한 크기를 인쇄하므로 확실하게 설정되지만 왜이 TextView의 크기가 조정되지 않습니까?
이 문제를 신속하게 해결할 수있는 사람이 있습니까? 댓글 후
아니요, 문제가 여전히 존재합니다 – Kuno
사용자의 셀 크기가 uitextview의 새 크기에서 올바르게 조정되지만 텍스트 뷰의 크기가 조정되지 않습니까? –
예, 셀 크기를 원하는만큼 높이로 조정할 수 있습니다 - 확인을 누릅니다. 하지만 포함 된 UITextView의 크기를 변경할 수 없으며 인터페이스 작성기에서 변경 한 경우에만 변경됩니다. 하지만 좀 더 동적으로 사용하고 싶습니다 ... TextView에서 프로그래밍 방식으로 변경 한 내용은 SIZE에 영향을주지 않습니다. – Kuno