Question

I'm building a UIScrollView inside a UITableViewCell so the cell can scroll left and right. I set the scroll view up in a storyboard without any AutoLayout constraints, and created an outlet for it. I put a UILabel inside the scroll view and then set the contentSize of the scrollview in code.

But when I run it in the simulator, I'm completely unable to scroll the cell left or right. What am I doing wrong?

Here's a little project I built showing it off in a simple case: http://cl.ly/0r2f0K1K3L1s

I'd include more code, but there's really not much more to it than what I outlined, as most of it is done in the storyboard. Is there something special to use storyboards and scroll views?

Was it helpful?

Solution

The problem is that you're using a storyboard with auto layout turned on as the source of your prototype cell with the scroll view inside it. Hence your attempt to set the scroll view's content size manually is failing. Either use internal constraints to set the contents size, or else create and configure the scroll view and its contents entirely in code so that auto layout doesn't apply to them, or else use a separate .xib as the source of your cell (so that you can turn off auto layout there).

I was able to get your scroll view working using constraints in your storyboard. I had to give both the scroll view and the label appropriate constraints.

OTHER TIPS

If anyone still facing issue try this.

If you are using custom cell class

try

self.contentView.isUserInteractionEnabled = true

or

cell.contentView.isUserInteractionEnabled = true

Go to Storyboard-> Remove using AutoLayout. Your cell can scroll. You dont set any constraint but system constraint will be fire in runtime.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top