0

I have an app that uses a UITableViewController, core-data, and UITextViews in the table rows which automatically adjust their vertical size based upon the size of the text they hold. The size adjustment is done the old fashioned pre-iOS8 (i.e no autosizing cells) way using tableView:heightForRowAtIndexPath and autolayout constraints. The cells also use auto-layout to position buttons such as a "clear text" button. That button is pinned to be 10pts inside of the superview's (UITableViewCell.contentView) trailing edge.

The code works fine in iOS 6, 7, and 7.1, but fails in iOS 8.1. The layout loads properly in iOS 8.1, but as soon as the user starts typing in the text box, the anchored buttons start jumping around and eventually are placed too far to the right, almost outside of the UITableViewCell.

iOS 7.1, CORRECT:

Buttons pinned correctly 10pts from cell trailing edge

iOS 8.1, INCORRECT:

Buttons too far to the right

If I comment out the line ("translation.text1Text = changedTextView.text;") which binds the changed text to the core data model, the problem doesn't show, but of course the textview doesn't resize properly either. So I'm thinking this may have something to do with how self.tableView beginUpdates/endUpdates interacts with auto-layout constraints in iOS 8.

I have put a full sample app with source code demonstrating the issue on https://github.com/SpencerY2/TestApp2 .

Not sure whether this might be related to either of these two other iOS8 autolayout issues: 1) Issue with Auto Layout on iOS 8 (code works perfectly on iOS 7) , 2) https://stackoverflow.com/questions/26461850/auto-layout-issue-in-ios-8-works-fine-in-ios-7

Any help would be most appreciated.

p.s. the app needs to run on iOS 6+ so using autosizing cells is not an option for now.

Community
  • 1
  • 1
spencery2
  • 511
  • 2
  • 10

1 Answers1

0

This issue appears to be the same as @Gallymon has in Autolayout problems with iOS8 with code that works fine on iOS7 and not the same as @BFar had in Issue with Auto Layout on iOS 8 (code works perfectly on iOS 7). I tried the suggested fix for Issue with Auto Layout on iOS 8 (code works perfectly on iOS 7), and it didn't work for me.

The ugly workaround I did was to create a transparent 1x1pt UIImageView (which I'll refer to as "anchorImage"), anchor its leading edge to the superview, and then anchor all the other widgets to the anchor image's trailing edge. I then need to readjust the horizontal location of the anchorImage if the device is rotated between portrait and landscape, but at least that is just one constraint I need to update instead of all of them.

I'm going to file a bug with Apple to have them investigate further.

If anyone sees something that I'm doing wrong and determines there's a better solution, I'm all ears...

I'm not marking this as the "correct" answer as maybe someone has a better idea.

UPDATE: Filed iOS bug 19108167 with Apple 12/1/14

Community
  • 1
  • 1
spencery2
  • 511
  • 2
  • 10