Note that there are some explanatory texts on larger screens.

plurals
  1. POUILabel position in a UITableViewCell fails on the first try
    primarykey
    data
    text
    <p>Just getting my feet wet with iOS development, so I hope I'm getting the right level of detail here...</p> <p>I have a <code>UILabel</code>, loaded in a Table cell created via a .xib. Actually several labels, one of which is of varying length (and therefore varying wrapped height). <code>heightForRowAtIndexPath</code>, etc. are properly overridden, and the required height for both labels is being calculated correctly and assigned to each's <code>.frame</code></p> <p>Once both sizes have been set, I set the frame.origin.y of the smaller (fixed length, always one row high) label to match that of the larger label. This works as far as can be seen stepping through <code>cellForRowAtIndexPath</code> but on initial display of the newly-created cell, the origin seems to be not-quite-vertically-centered in the container, as opposed to stuck up top. </p> <p>After clicking "through" the cell to a different view, and returning to the (now-reused, and presumably already properly-sized container), the position is set as before, and it appears where I expected it to.</p> <p>It <em>seems</em> like the container is being resized after <code>cellForRowAtIndexPath</code> returns, and that somewhere in there a new position is found for our label; this would explain why reusing the cell later fixes the problem.</p> <p>I've tried every apparently-sane combination of inner and outer Mode and Baseline settings, stretch settings, etc. At a loss for explanations and/or workarounds.</p> <p><strong>Update:</strong></p> <p>A suggestion on the <a href="https://stackoverflow.com/questions/8352530/changing-the-position-of-custom-uibutton-in-custom-uitableviewcell">Changing the position of custom UIButton in custom UITableViewCell</a> question solved the problem. The solution was to subclass <code>UITableViewCell</code> and override <code>layoutSubviews</code>, thereby getting a chance to re-position the sub-elements after the TableView had done its normal positioning. Will close this once either that person responds here, or the bounty expires and I'll answer myself, with code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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