我尝试使用sliderChanged(滑块值已更改)方法更改单元格内的标签(titleOutlet),但我不知道如何访问标签插座,就像我们使用cellForRowAtIndexPath一样。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomisationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
CustomisationObject *movie = (localArray)[indexPath.row];
cell.titleOutlet.text = movie.localChannel;
cell.sliderOutlet.value = movie.localValue.integerValue;
return cell;
}
- (IBAction)sliderChanged:(id)sender {
UISlider *slider = (UISlider *)sender;
NSLog(@"%f", [slider value]);
CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:hitPoint];
NSLog(@"%ld", (long)indexPath.row);
}
答案 0 :(得分:3)
假设您拥有单元格的indexPath
,则可以使用:
CustomisationCell *cell = (CustomisationCell *)[self.tableView cellForRowAtIndexPath:indexPath];
NSLog(@"%@", cell.titleOutlet.text);
答案 1 :(得分:0)
我建议在UISlider上使用标记并将其设置为行索引,以便稍后获取所需的行。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomisationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
CustomisationObject *movie = (localArray)[indexPath.row];
cell.titleOutlet.text = movie.localChannel;
cell.sliderOutlet.value = movie.localValue.integerValue;
cell.sliderOutlet.tag = indexPath.row;
return cell;
}
- (IBAction)sliderChanged:(id)sender {
UISlider *slider = (UISlider *)sender;
NSLog(@"%f", [slider value]);
NSInterger rowIndex = [sender tag];
CustomisationCell *cell = (CustomisationCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:rowIndex inSection:0];
cell.titleOutlet.text = "new text from slider";
}