0

I'm trying to reduce set a specific tableview cell's height to zero depending on particular conditions. I have used the tableview delegate methods as so:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 1) {
        return 0;
    }
    return 45.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Only indicating the necessary code to hide the cell 
       if (indexPath.row == 1) {
          cell.hidden = YES;
       }
}

It works as it should , hiding the cell. However, I get a warning which I am weary about incase the app doesn't get approved. Below is the log:

Unable to simultaneously satisfy constraints.
(
"<NSLayoutConstraint:0x7fb903c3bab0 UILabel:0x7fb903c3afb0'Vehicle    Type'.bottom == UITableViewCellContentView:0x7fb903c3ae90.bottomMargin - 4>",
"<NSLayoutConstraint:0x7fb903c3bb50 UILabel:0x7fb903c3afb0'Vehicle Type'.top == UITableViewCellContentView:0x7fb903c3ae90.topMargin + 4>",
"<NSLayoutConstraint:0x7fb903c8c760 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fb903c3ae90(0)]>"
)

NB: I am using a custom tableviewcell

DrPatience
  • 1,736
  • 2
  • 15
  • 33
  • If you do not want to show a particular cell, you can simply remove it from the data source. – Eric Qian Sep 02 '15 at 07:20
  • thanks, I'm aware of that but it needs to be there as the same datasource which is a mutable array is used in other functions. – DrPatience Sep 02 '15 at 07:21
  • As you can see the system is complaining for "Layout constraint breaking". You must have somewhere put the wrong constraint. – Rohit Kumar Sep 02 '15 at 07:28
  • @DrPatience check out this link it will help you http://stackoverflow.com/questions/25059443/what-is-nslayoutconstraint-uiview-encapsulated-layout-height-and-how-should-i – Harish Sep 02 '15 at 07:44

2 Answers2

1

OK, if you cannot delete the object from data source for some reason, then I think you need to carefully handle it in your data source methods instead of set the rowHeight to 0 to "hide the cell". For example, if you want to "hide" the first cell, you probably need to do something like:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count - 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    object = self.dataSource[indexPath.row + 1];
    ......
    return cell;
}
Eric Qian
  • 2,246
  • 1
  • 18
  • 15
0

The console output tells me that the cell contains a label, the top and bottom of which are constrained to have a 4 point gap to the cell's content view. When the cell has a height of zero (or anything less than 8 points), the label would need to have a negative height to satisfy those constraints. This isn't allowed, so Autolayout needs to ignore at least one of your constraints. It will start by ignoring the constraint with the lowest priority. However, in your case both the top and bottom constraints have a priority of 1000. Autolayout deals with this ambiguity by breaking one of the constraints and logging the warning.

You can overcome this problem by changing the priority of one of your constraints to 999. You can also test the fix in Interface Builder: adjust the cell's height to zero, and if a red error appears, your constraints are ambiguous at zero height.

I don't believe this would be grounds for AppStore rejection.

johnpatrickmorgan
  • 2,372
  • 2
  • 13
  • 17