Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

ios - Storyboard auto layout places view in table cell with fixed trailing-to-superview constraint to far left

I placed an UIImageView at the right side of a table view cell and added a trailing constraint to the cell of 20.

Yet the image ends all the way at the left of the cell when I run the app.

My table view controller code is very basic:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCell(withIdentifier: "SailboatCell", for: indexPath) as! SailboatTableViewCell

    return cell
}

The identifier is correct and I also set the class of cell.

I've done auto layout a lot and have no idea what I could be missing here.

On a device the images are on the right side when the app starts but end up on the left on newly created cells when I start scrolling. Things reset themselves a bit when I put the device in landscape and then portrait again.

No auto layout warnings are printed.

Earlier I had other UI elements on the cell that were nicely placed (left-to-right) as expected. Only the image view acted weird. I deleted all other UI elements to avoid any interference.

enter image description here

EDIT: I've recreated the cell and all is fine know. No idea what is was.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It might because you have set semanticContentAttribute to .forceRightToLeft for the cell or UIView.appearance().

According to Apple document for semanticContentAttribute:

A semantic description of the view’s contents, used to determine whether the view should be flipped when switching between left-to-right and right-to-left layouts.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...