For my project, I need to show a doctors list with a lot of information, for this I create a custom cell programmatically. Here is how my cell's view is structured :
Cell.contentView
| --> UIView
| --> UILabel (Title)
| --> UILabel (Subtitle)
| --> UIView (a simple separator, with a 1px height constraint)
| --> UILabel (Address, multilines)
This is a simplified structure of what I really have, but it's enough to bring the warning.
And this is the warning :
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]>
My constraints :
The only height constraint I have is on my separator view, labels are pinned to superview by all the sides to allow my cell's height to be calculating by autolayout. If I remove my separator view and pin the top of the address label directly to the bottom of the subtitle label, the warning disappears. If I add a height constraint on one label, the warning comes back.
Some classic but maybe interesting methods :
For getting the height of a specified row :
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 don't understand what I'm doing wrong, and what I have to do to remove this warning, I've tried to download this example form raywenderlich.com and simply add a height constraint on a label, I've got the same kind of warning.
One more thing, I have to be fully compatible with ios 7, that's why i'm not using the new features introduced by the sdk 8.