carekit-apple / CareKit

CareKit is an open source software framework for creating apps that help people better understand and manage their health.
https://www.researchandcare.org
Other
2.41k stars 443 forks source link

Unsatisfiable constraints for Insights View Controller if instantiated with zero widgets #177

Closed UberJason closed 7 years ago

UberJason commented 7 years ago

In CareKit 1.2, if OCKInsightsViewController is instantiated without any widgets, for example:

let viewController = OCKInsightsViewController(insightItems: insights, patientWidgets: [], thresholds: nil, store: storeManager.store)

Then when the OCKInsightsViewController appears on screen for the first time, Auto Layout prints to console warning about simultaneously satisfying constraints:

[LayoutConstraints] 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. 
(
    "<NSLayoutConstraint:0x608000296440 UIStackView:0x7ff4c4f1e8c0.height >= 90   (active)>",
    "<NSLayoutConstraint:0x6080002963a0 V:|-(0)-[UIStackView:0x7ff4c4f1e8c0]   (active, names: '|':OCKInsightsTableViewHeaderView:0x7ff4c4f1d3f0 )>",
    "<NSLayoutConstraint:0x608000295130 UIStackView:0x7ff4c4f1e8c0.bottom == OCKInsightsTableViewHeaderView:0x7ff4c4f1d3f0.bottom   (active)>",
    "<NSLayoutConstraint:0x6080002978e0 OCKInsightsTableViewHeaderView:0x7ff4c4f1d3f0.height == 0   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x608000296440 UIStackView:0x7ff4c4f1e8c0.height >= 90   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-23 23:49:20.333109-0400 Nerve Pain[19504:576028] [LayoutConstraints] 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. 
(
    "<NSLayoutConstraint:0x6080002978e0 OCKInsightsTableViewHeaderView:0x7ff4c4f1d3f0.height == 0   (active)>",
    "<NSLayoutConstraint:0x60000028f4b0 V:|-(0)-[UIStackView:0x7ff4c4f1e8c0]   (active, names: '|':OCKInsightsTableViewHeaderView:0x7ff4c4f1d3f0 )>",
    "<NSLayoutConstraint:0x60000028f550 UIStackView:0x7ff4c4f1e8c0.bottom == OCKInsightsTableViewHeaderView:0x7ff4c4f1d3f0.bottom   (active)>",
    "<NSLayoutConstraint:0x60000028f5f0 UIStackView:0x7ff4c4f1e8c0.height >= 90   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60000028f5f0 UIStackView:0x7ff4c4f1e8c0.height >= 90   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

This appears to be because the OCKInsightsTableViewHeaderView is constraining itself to have height >= 90, while the tableView in OCKInsightsViewController constrains the height of its headerView to 0 if the number of widgets is 0. One easy fix is to reduce the priority of the header view's internal height constraint to 999 so it doesn't clash with the constraint imposed by its owner.

I will submit a PR with a fix for the issue shortly.

kelseydedoshka-apple commented 7 years ago

@UberJason - thanks for pointing this out as well as submitting a PR for the fix. Closing this issue as the fix has been merged.