我有一个带滑块和标签的自定义表格视图单元格。我在自定义单元格上为滑块和标签创建了一个属性。我想将滑块值传输到标签。这就是我的束缚:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *cellInfo = [[self.sections objectAtIndex:currentTab] objectAtIndex:indexPath.row];
HLMagnitudoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[cellInfo objectForKey:@"cell"] forIndexPath:indexPath];
UIImageView *radioIndicator = (UIImageView *)[cell.contentView viewWithTag:200];
radioIndicator.image = (currentBullet != indexPath.row) ? [UIImage imageNamed:@"RadioOff"] : [UIImage imageNamed:@"RadioOn"];
UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];
av.backgroundColor = [UIColor clearColor];
av.opaque = NO;
av.image = [UIImage imageNamed:@"NewsSeparetor.png"];
cell.backgroundView = av;
cell.slider.maximumValue = 100;
cell.slider.minimumValue = 1;
cell.slider.continuous = TRUE;
cell.slider.tag = 1;
cell.slider.value = [cell.label.text intValue];
[cell.slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
return cell;
}
- (void)sliderChanged:(UISlider *)slider
{
}
答案 0 :(得分:0)
在单元格中创建滑块并为每个滑块设置标记值: 例如:
slider.tag=1
注册更新值时要调用的方法:
[slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
然后在您的方法中,您将能够使用标记获取滑块的值:
-(void)sliderChanged:(UISlider *)sender {
int tag = sender.tag;
if (tag ==1 ) //Update the label
slider1Label.text=[NSString strinWithFormat:@"%d",sender.value]
}
else if (tag == 2){
//Do something else
}
}