내 프로젝트의 경우 많은 정보가 담긴 의사 목록을 표시해야합니다.이를 위해 프로그래밍 방식으로 사용자 지정 셀을 만듭니다. 다음은 내 셀의보기가 구성되는 방식입니다.autolayout이있는 사용자 지정 UITableViewCell이 경고를 발생시킵니다.
Cell.contentView
| --> UIView
| --> UILabel (Title)
| --> UILabel (Subtitle)
| --> UIView (a simple separator, with a 1px height constraint)
| --> UILabel (Address, multilines)
이것은 실제로 갖고있는 단순화 된 구조이지만 경고를 표시하는 것으로 충분합니다.
그리고 이것은 경고입니다 :
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x14f9a790 V:|-(11)-[UILabel:0x16058ea0'DR.NAME'] (Names: '|':DoctorHealthInformationView:0x16058f70)>",
"<NSLayoutConstraint:0x14f86300 V:[UILabel:0x16058ea0'DR.NAME']-(1.5)-[UILabel:0x160670e0'Chirurgien Dentiste']>",
"<NSLayoutConstraint:0x14f86390 V:[UILabel:0x160670e0'Specialty']-(9)-[UIView:0x14e0fde0]>",
"<NSLayoutConstraint:0x14f9ab20 V:[UIView:0x14e0fde0]-(8)-[KDCellLabel:0x14f90d10'Address\naddres...']>",
"<NSLayoutConstraint:0x14f9ab50 KDCellLabel:0x14f90d10'Address\naddres...'.bottom == DoctorHealthInformationView:0x16058f70.bottom - 10>",
"<NSLayoutConstraint:0x14f97a80 V:|-(0)-[DoctorHealthInformationView:0x16058f70] (Names: '|':CustomDoctorCell:0x1605a890'OnlineCustomDoctorCell')>",
"<NSLayoutConstraint:0x14f88840 V:[DoctorHealthInformationView:0x16058f70]-(0)-[UIView:0x14f930d0]>",
"<NSLayoutConstraint:0x14f889b0 V:[UIView:0x14f930d0(1)]>",
"<NSLayoutConstraint:0x14f9ae10 UIView:0x14f9d330.bottom == CustomDoctorCell:0x1605a890'OnlineCustomDoctorCell'.bottom>",
"<NSLayoutConstraint:0x14f9b120 V:[UIView:0x14f9d330(4)]>",
"<NSLayoutConstraint:0x14f9af40 V:[UIView:0x14f930d0]-(0)-[UIView:0x14f9d330]>",
"<NSLayoutConstraint:0x14f93020 'UIView-Encapsulated-Layout-Height' V:[CustomDoctorCell:0x1605a890'OnlineCustomDoctorCell'(44)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x14f86390 V:[UILabel:0x160670e0'Specialty']-(9)-[UIView:0x14e0fde0]>
내 제약 : 내가 가진 유일한 높이 제약 조건 내 분리보기에
가, 레이블 모든 측면에서 수퍼에 고정되어 내 셀의 높이가 자동 레이아웃에 의해 계산되도록하십시오. 구분 기호보기를 제거하고 주소 레이블의 맨 위를 자막 레이블의 맨 아래에 직접 고정하면 경고가 사라집니다. 하나의 레이블에 높이 제한을 추가하면 경고가 다시 나타납니다.
일부 고전하지만 어쩌면 흥미로운 방법 :
지정된 행의 높이를 얻기 위해 :
TableViewController :
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
Doctor *doctor = (Doctor *)[_doctorsToShow objectAtIndex:indexPath.row];
static CustomDoctorCell *sizingCellClassic = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sizingCellClassic = [[CustomDoctorCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:classicDoctorCellIdentifier
forDoctor:doctor
showSpecialty:YES
withAppointmentStyle:YES];
});
[sizingCellClassic updateContentForDoctor:doctor];
return [CustomDoctorCell getCellHeightForCell:sizingCellClassic];
}
CustomDoctorCell :
+ (float) getCellHeightForCell:(CustomDoctorCell *)doctorCell
{
[doctorCell setNeedsLayout];
[doctorCell layoutIfNeeded];
CGSize size = [doctorCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height;
}
I 돈을 ~ 미만 내가 잘못하고있는 것을 지켜라.이 경고를 제거하기 위해해야 할 일은 this example 형태의 raywenderlich.com을 다운로드하고 레이블에 높이 제한을 추가하기 만하면된다. 나는 같은 경고를 받는다. 내가 셀의 초기 높이가 수직보다 더 가능성이 작다는 SDK (8)
iOS9에서 하나의 높이 제한 조건 우선 순위를 1000 미만으로 설정하면됩니다. 이유를 이해할 수 없지만 자동 레이아웃 제약 조건을 여러 번 확인했는데 문제가 없어야했습니다. UITableViewCell의 자동 레이아웃은 여러 번 두통이되었습니다 ... –