Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableViewCells scroll horizontally using auto layout when changing to portrait mode
    text
    copied!<p>I am creating a screen that is primarily a UITableView with cells that have differing controls and layouts. I had the tableview working great until I switched to portrait mode where it allowed the tableview cells to scroll horizontally. The cells should never scroll horizontally; only vertically. When I navigate to the screen and I'm already in portrait mode it works fine, even going to landscape and back to portrait.</p> <p>Some things to note are that I'm using and iPad, storyboards, auto layout, and the UITableViewCell is custom and does not have a nib (though it does the same thing when I tried using a nib). All controls and layout constraints are added programmatically. I am using a custom view controller with a view inside of it. Inside of the view I have the tableview and a toolbar. If I remove the view so that the tableview is directly under the custom view controller it works fine, but then I can't have the toolbar.</p> <p>Here is the test code I am using to troubleshoot the problem:</p> <pre><code>// Remove all existing subviews for(UIView *subView in self.contentView.subviews) { [subView removeFromSuperview]; } UILabel *testLabel = [[UILabel alloc] init]; testLabel.text = @"Test"; [testLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; self.contentView addSubview:testLabel]; NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(testLabel); NSString *format = [NSString stringWithFormat:@"V:|-[testLabel]-|"]; NSArray *constraintsArray = [NSLayoutConstraint constraintsWithVisualFormat:format options:nil metrics:nil views:viewsDictionary]; //[self.contentView addConstraints:constraintsArray]; </code></pre> <p>The scrolling works as intended until I uncomment the line to add the constraints. This code is in a method of my custom cell and gets called every time a cell is dequeued. I've tried adding the contraints individually, without using the visual format, with no luck. I have also done some research and found the code that removes the contraints from the cell and adds them to the contentView, but that hasn't helped either.</p> <p>What do I need to do to keep the cells from scrolling horizontally when changing from landscape to portrait mode?</p> <p>MORE INFO: After some more debugging I found that the table view's content size is not shrinking horizontally. The width is staying at 1024.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload