2014-11-13 2 views
0

UITableViewCell의 크기를 올바르게 지정하여 UILabel 및 UITextView에 맞춰 레이블 내의 모든 텍스트와 textView를 볼 수있게하려고합니다.UITextView를 사용하여 UITableViewCell의 AutoLayout

이제 textView에 적절한 크기를 얻는 데 문제가 있습니다. 지금, 나는 내 펜촉 아래 레이블을 통해 마지막으로 셀의 아래로 셀의있는 contentView의 상단을 고정 제약이 있는지 확인했습니다

if (_prototypeCell == nil) { 
     _prototypeCell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([DDDataDetectingDetailCell class]) owner:nil options:0] lastObject]; 
    } 

    [_prototypeCell setFrame:CGRectMake(0, 0, CGRectGetWidth(self.tableView.frame), 1)]; 
    [_prototypeCell configureForItem:self.items[indexPath.row]]; 
    [_prototypeCell setNeedsLayout]; 
    [_prototypeCell layoutIfNeeded]; 

    CGSize size = [_prototypeCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; 
    return size.height + 1; 

: 여기 내 레이아웃 코드입니다. 또한 셀에는 수평 치수를 따라 연결하는 제약이 있습니다.

(lldb) po _prototypeCell 
<DDDataDetectingDetailCell: 0x79bd4700; baseClass = UITableViewCell; frame = (0 0; 320 1); autoresize = RM+BM; layer = <CALayer: 0x79bbba90>> 

(lldb) po _prototypeCell.detailTextView 
<UITextView: 0x7b9ffc00; frame = (15 1; 290 0); text = 'No need to pay -- Just le...'; clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x79bce590>; layer = <CALayer: 0x79bd6910>; contentOffset: {0, 0}; contentSize: {290, 0}> 

따라서 텍스트 뷰가 나타납니다 : 나는 텍스트 뷰 셀을 인쇄하는 경우, 나는이 얻을 수 있기 때문에

(width=486.5, height=61.5) 

이 홀수 :이 크기를 인쇄 할 경우, 나는 다음과 같은 수 올바른 너비가 될 수는 있지만 어떤 이유로 인해 구속 조건에 따라 높이가 계산되지 않습니다. 여기

내 layoutSubviews 방법입니다 :

- (void)layoutSubviews { 
    [super layoutSubviews]; 
    self.mainLabel.preferredMaxLayoutWidth = self.mainLabel.frame.size.width; 
    [super layoutSubviews]; 
} 

그리고 여기 내 제약의 그림입니다 :

constraints on my cell

가 왜 -systemLayoutFittingSize:에서이 펑키 너비는 무엇입니까?

UPDATE

내가 잘못 (width=456.5, height=32.5)

+0

셀 클래스 내부의 UITextView에'self.textView.scrollEnabled = NO; '를 설정 했습니까? – Zhang

+0

예, 불행히도,이 작업을하지 못했습니다. –

+0

인터페이스 빌더를 사용하여 구현 했습니까? – Zhang

답변

0

로 다시있는 ScrollView 보고서의 intrinsicContentSize 이후 (물론, 스크롤 뷰)에 UITextView에 제약을 구성하고 생각 나는 당신을 믿어요 레이블 및 텍스트보기의 내용 압축 저항을 1000 (필수)로 설정해야합니다. 무슨 일이 일어나고 레이블과 텍스트보기는 내용을 압축하고 있습니다.

텍스트보기에서 높이 제한을 만들고 텍스트보기의 contentSize로 설정해야 할 수도 있습니다.

+0

도이 문제를 시도했습니다. 이 작업을 수행 할 수있는 유일한 방법은 하위 클래스를 만들고 본질적인 콘텐츠 크기를 변경하는 것입니다. –

관련 문제