Static or Prototype UITableViewCell subviews are resized incorrectly in Storyboard on Xcode 6.1.1, iOS 8.1 SDK

前端 未结 1 1584
臣服心动
臣服心动 2021-01-07 05:24

So I updated to Xcode 6.1 earlier and 6.1.1 today. I notice that there\'s an issue while using Static / Prototype UITableViewCell (or Prototype UICollection

相关标签:
1条回答
  • 2021-01-07 05:59

    I had the same problem, and have found a solution that works for me. It seems like Xcode is not (always) recording the initial frame sizes of table view cells and their content views.

    If you open the storyboard in another editor (preferably with Xcode closed), and have a look at your cells you should find the following:

    <tableViewCell ...>
       <autoresizingMask .../>
       <tableViewCellContentView ...>
    

    A number of keys and attributes above have been omitted for brevity. What is missing from the above is rect keys for the tableViewCell and the tableViewCellContentView. Autoresizing relies on the initial frame size to determine offsets from the right/bottom. Without the initial frame size (given by the rect keys) the initial frame is calculated as 0,0,0,0 which doesn't affect items anchored to the top or left, but does (of course) affect items anchored to the right/bottom.

    To fix the issue ensure there is a (correct) rect key for every tableViewCell and tableViewCellContentView, e.g.:

    <tableViewCell ...>
       <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
       <autoresizingMask .../>
       <tableViewCellContentView ...>
          <rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
    

    If you have an accessory view enabled for a cell you might need to reduce the content view's width for that cell. The width / height shown in Xcode (greyed out) for the content view is what should be put in to the storyboard (by hand).

    I should add that Xcode does not appear to remove these rect keys from the storyboard when editing, so after edits are complete the storyboard should still be entirely editable with Xcode.

    0 讨论(0)
提交回复
热议问题