You can do this because you have some tricks, first of all you need to set the goal for UISlider as some, as suggested, the other point is to get the selected line, which you can save in the tag property indexPath.row , as in the following code :
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell let slider = UISlider(frame: CGRectMake(0, 0, 100, 44)) slider.userInteractionEnabled = true slider.minimumValue = 1 slider.maximumValue = 100 slider.value = 50 slider.continuous = true
Another problem is the UILabel text, which you can get by getting the exact representation inside the cell, for example, in the following code:
func sliderValueChanged(sender: AnyObject) { var slider = sender as! UISlider let cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: slider.tag, inSection: 0)) as UITableViewCell!
In the above code, I only set the exact number inside the UITableViewCell to show the path, but the highly recommended way is to UIView over all the UIView and find your UILabel , as in the method suggested in this question Find the UILabel in the UIView in Swift , because the number may change.
As some people have said, itβs easier to set up a custom cell through Interface Builder, but it is up to you.
Hope this helps you.
source share