Question

So I have a nicely working UITableView consisting of 3 rows (each including and image, and a varying number of text fields).

Now the 4th row has a UISegmentedControl. As soon as I added it, the UITableView lags/jumps/skips. When I take it away again, everything is smooth.

How can I add the UISegmentedControl and still have smooth scrolling?

Was it helpful?

Solution

Had a similar problem. After the segmented control goes out of view, scrolling back to it is choppy. The problem could be the initialization.

First check if you use the "dequeueReusableCellWithIdentifier" correctly (maybe you missed giving your custom cell a unique ID ?)

Second check if you don't do removeAllSegments and insertSegmentWithTitle each time in cellForRowAtIndexPath. Add some int to your custom cell to tell you if it is a new cell or a reused cell with a certain number of segments. Then after you "dequeueReusableCellWithIdentifier" if the cell has the exact number of segments no clearing and adding is needed.

In my case I did the checked the first but not the second which made my scrolling lag. It seems that the segment clearing and adding is a costly operation.

Hope this helps.

OTHER TIPS

I had a similar problem as well. Due to business logic my app should update the cells for an interval of a few seconds. Each cell had a segmented control and I was removing all segments and adding them again for each update. After some time the scrolling gets incredibly slow. I solved the problem removing/adding the segments only when it was really necessary instead of doing this for each update. Also I'm using "dequeueReusableCellWithIdentifier". It is working fine now.

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