UISlider not sliding in prototype cell
Asked Answered
D

3

3

I have designed a prototype cell in a Storyboard's view controller, but unfortunately the UISlider in the cell is not sliding.

Note:- Autolayout is enabled for this storyboard.

Design:-

enter image description here

Here is code:- to render the cell in UITableview

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell;
    if(indexPath.row!=self.arrSelectRecipientsImages.count-1 )
    {

        cell = [tableView dequeueReusableCellWithIdentifier:@"selectReciptenceTabCell" forIndexPath:indexPath];

    }
    else
    {
        cell = [tableView dequeueReusableCellWithIdentifier:@"selectNearbyTabCell" forIndexPath:indexPath];
        UISlider *sliderNearby = (UISlider *)[cell.contentView viewWithTag:199];
        lblDistance = (UILabel *)[cell.contentView viewWithTag:190];
        sliderNearby.userInteractionEnabled = YES;
        [sliderNearby setThumbImage:[UIImage imageNamed:@"NearbyCircle"] forState:UIControlStateNormal];
        [sliderNearby addTarget:self action:@selector(sliderNearbyAction:) forControlEvents:UIControlEventValueChanged];
  }
return cell;
}
Decoct answered 28/12, 2015 at 6:47 Comment(4)
I think didSelectRow touch delegate is conflicting with slider touch.Mention
A slider should work in a table view, please describe the problem with more details.Katsuyama
The problem is very simple, on sliding the slider it's is not sliding.@KatsuyamaDecoct
The problem must be indeed very simple, however your description is not sufficient to identify it. Even though identifying the problem in this case will mist likely provide an obvious solution, I suggest that you try to provide more details. The easiest setup with a static table view and a slider works well, it takes a minute to build and you can start from there applying your specific features and seeing when it becomes broken. Other than that there's also a responders chain and the actual layout that can be easily verified and the results described at the question.Katsuyama
T
1

The code is working fine I think. Also no need to set user interaction.

Here is the example code may you get help form it. It is working fine with autolayout.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

    UILabel *lblTitle = (UILabel *)[cell viewWithTag:100];
    lblTitle.text = @"Hi";

    UISlider *slider = (UISlider *)[cell viewWithTag:101];
    slider.value = 0.2;
    slider.tag = indexPath.row;
    [slider addTarget:self action:@selector(sliderNearbyAction:) forControlEvents:UIControlEventValueChanged];
    return cell;
}

- (void)sliderNearbyAction:(UISlider *)sender{
    NSLog(@"Slider %ld Value : %.2f",(long)sender.tag, sender.value);
}

OUTPUT with Log :

enter image description here

Autolayout Screenshot :

enter image description here

Tocology answered 28/12, 2015 at 9:12 Comment(4)
Thanks! but can you post the screenshot of the autolayout used in UISlider.Decoct
@Decoct Sure. Updated.Tocology
@Decoct Oh! But where is the issue. I think it's constraints issue. Else it is working fine.Tocology
I don't know.. what causing the problem..Layout is working fine.. I guess. I am checking the touch on cell view..Decoct
D
1

Well, the problem was very silly, I have not provided height for cell in different index-path.That's why the last cell i.e the slider cell was showing but it's height was 30, so any tap or gesture outside that region was not responding.

Decoct answered 29/12, 2015 at 12:51 Comment(0)
H
1

Maybe the issue was in isUserInteractionEnabled. If you have any interactable elements as subviews of cell (not of contentView), you need to set

cell.contentView.isUserInteractionEnabled = false

for the cell.

Hedjaz answered 28/9, 2020 at 20:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.