ios - UISlider 不在原型(prototype)单元格中滑动

标签 ios objective-c uitableview ios9 uislider

我在 Storyboard 的 View Controller 中设计了一个原型(prototype)单元格,但不幸的是单元格中的 UISlider 没有滑动。

注意:-此 Storyboard启用了自动布局。

设计:-

enter image description here

这是代码:-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;
}

最佳答案

我认为代码运行良好。 也无需设置用户交互。

这是示例代码,您可以从中获得帮助。它与自动布局配合得很好。

- (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);
}

带日志的输出:

enter image description here

自动布局截图:

enter image description here

关于ios - UISlider 不在原型(prototype)单元格中滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34488856/

相关文章:

ios - iPad 3 上的启动画面

objective-c - 在 UIViewController 中模拟 UIView

ios - Images.xcassets 中的 LaunchImage 与 Launchscreen.xib

UINavigationController 中的 UITableView 旋转后进入导航栏

iPhone:当 UITableView 滚动到 60 多个自定义单元格时应用程序崩溃

ios - 在 swift 3 中出列可重用单元的正确方法(最佳实践)是什么?

ios - 从 NSURLConnection 收集数据

ios - 在iOS模拟器中检测UIButton上的长按

javascript - 如何使用 JavaScriptCore 将 javascript 对象转换为 NSDictionary

ios - UITableViewCell 之外的标签为当前屏幕上的单元格更新