I'm trying to change the label (titleOutlet) within my cell using my sliderChanged (slider value changed) method but I don't know how to access the label outlet like we do it 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);
}
有帮助吗?

解决方案

Assuming you have the indexPath of the cell, you could use:

CustomisationCell *cell = (CustomisationCell *)[self.tableView cellForRowAtIndexPath:indexPath];
NSLog(@"%@", cell.titleOutlet.text);

其他提示

I would suggest using a tag on the UISlider and set it to the row index so you can get the row you want later.

- (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";

}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top