【发布时间】:2011-11-03 23:14:10
【问题描述】:
我的每个表格单元格都有一个滑块和一个标签来显示其值。如果我在保持单元格内的所有触摸的同时移动滑块,则标签会按预期更新。但是,如果在拖动滑块时,触摸跨越到另一个单元格,则第二个单元格的标签会在第一个单元格滑块的拇指移动时更新。如何将标签更改限制为滑块事件起源的第一个单元格?
-(IBAction)sliderChanged:(id)sender forEvent:(UIEvent*)event
{
NSSet *allTouches = [event allTouches];
UITouch *firstTouch = [[allTouches allObjects] objectAtIndex:0];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:[firstTouch locationInView:self.tableView]];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell)
{
UISlider *slider = (UISlider*)sender;
UILabel *sliderValueLabel = (UILabel*)[cell viewWithTag:kSliderValueLabelTag];
sliderValueLabel.text = [NSString stringWithFormat:@"%0.2f", slider.value];
}
}
【问题讨论】:
标签: ios uitableview uislider uitouch