Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble while rotating device #14

Closed
smoscar opened this issue Dec 15, 2014 · 3 comments
Closed

Trouble while rotating device #14

smoscar opened this issue Dec 15, 2014 · 3 comments

Comments

@smoscar
Copy link

smoscar commented Dec 15, 2014

Hello mate. I have been using your solution to create auto-layout UITableViews and UITableViewCell basically since you released it for iOS 7, it is great

Back then I made a few modifications to allow different constraints to be placed for portrait and landscape orientations, basically it was done by adding an observer for orientation changes to the table view cell that calls "setNeedsUpdateConstraints" and at the "updateConstraints" method I remove and add the constraints needed to change the layout on the cells.

It was working ok on iOS 7 but now on iOS 8 it doesn't seem to work correctly, I already updated it to use UITableViewAutomaticDimension with no luck. Do you have any ideas why this could be happening?

@smileyborg
Copy link
Owner

Glad to hear it's been helpful. As far as the issue you're seeing with iOS 8, here are the first two things I would check:

  1. Your rotation callbacks might not be happening on iOS 8 -- I would double check those are still working as expected first.
  2. When your rotation callback happens and you call setNeedsUpdateConstraints, is updateConstraints getting called on your cell and are your constraints being updated? Which view do you call setNeedsUpdateConstraints on?

Another recommendation I have is to consider moving away from observing the rotation notifications, and move towards making decisions using the new Adaptivity APIs in iOS 8 (assuming your deployment target is set to iOS 8 only). Instead of having the cells themselves try to handle rotations and remove constraints, I would have the table view controller implement the new viewWillTransitionToSize:withTransitionCoordinator: method, and inside that method call reloadData on your table view. I recently wrote up a related post on Stack Overflow which you might find helpful: http://stackoverflow.com/a/27409619/796419

Then in the resulting calls to tableView:cellForRowAtIndexPath: from reloading the table, you can configure your cells for the new orientation -- I specifically recommend using a separate cell reuse identifier for your portrait vs landscape cell types to improve performance.

Good luck getting things working!

@smoscar
Copy link
Author

smoscar commented Dec 15, 2014

Thank you for your comments

As far as the two questions you pointed out I am sure that the callbacks are being sent and the setNeedsUpdateConstraints is called on the tableviewcell

Since I am targeting iOS 8 only I am going to look at your suggestion with the viewWillTransitionToSize:withTransitionCoordinator: methods, best regards

@smoscar
Copy link
Author

smoscar commented Dec 16, 2014

Hello mate I just realize what the problem was.

In iOS 7 the cell's contentView was automatically pinned to the cell and apparently in iOS 8 you have to add constraints so that the contentView has the same size and origins as the cell itself, otherwise it has some issues specially when the contentView grows or changes

Hope it helps you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants