UISlider doesn't work inside UITableViewCell

2019-07-19 08:35发布

问题:

I want to put a slider with two selector points as a range into a UITableViewCell (in static UITableView). I tried this library https://github.com/muZZkat/NMRangeSlider

But It doesn't work. Sometimes It response, sometimes not.

After that I tried with a simple UISlider and I got the same result.

I tried to add the UISlider programmatically and with the storyboard. Both options. The same result.

回答1:

I'm a Javier's coworker. We find a third-party library (Left Menu like Facebook) that listen swipe gesture. We disable swipe gesture in the left menu (app cross) then works fine.



回答2:

Considering this is happening with the stock slider and that library, the issue is probably a conflicting gesture recognizer. UITableViewCells have a gesture recognizer to detect a swipe (to delete) as well as scrolling and tapping for selection. I wouldn't be surprised if one or more of these gesture recognizers on the table and cell were stepping on the slider's own gesture recognizer. Check out this link and see if it helps.

Pan gesture interferes with UISlider



回答3:

The issue is that the content view is layered above of you custom cell view.

To fix this all you need to do is: add cell.sendSubviewToBack(cell.contentView) in cellForRowAtIndexPath