Для моего проекта мне нужно показать список врачей с большим количеством информации, для этого я создаю специальную ячейку программно. Вот как структурирован вид моей ячейки:Пользовательский 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;
}
Я не под что я делаю неправильно, и что мне нужно сделать, чтобы удалить это предупреждение, я попытался загрузить форму this example form raywenderlich.com и просто добавить ограничение на высоту на ярлыке, у меня такое же предупреждение. более
Одна вещь, я должен быть полностью совместим с прошивкой 7, поэтому я не использую новые функции, появившиеся в SDK 8.
Установка одного ограничения на ограничение роста ниже 1000 работает для меня в iOS9. Я все еще не понимаю, почему, я много раз проверял ограничения автоматического макета, и у них не должно быть проблем. Автоматическая компоновка UITableViewCell была моей головной болью столько раз ... –