我在故事板的视图控制器中设计了一个原型单元,但不幸的是UISlider
细胞内不滑动。
Note:-此故事板启用了自动布局。
Design:-
这是代码:-渲染单元格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);
}
带日志的输出:
自动布局截图:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)