runmad
runmad

Reputation: 14886

Update UITableView titleForFooterInSection for UISlider's valueChanged?

I have a UITableViewCell which has a UISlider in it. I have a footer text for the tableview that I would like to update with the value of the UISlider.

However, calling [self.tableView reloadData]; does not work for the UISlider, as it is too many calls. I am able to update the cell correctly (it also shows the value), but I am unable to update the footer text. I have tried:

[self tableView:self.tableView titleForFooterInSection:0];

But it doesn't work..

Upvotes: 2

Views: 2208

Answers (1)

Costique
Costique

Reputation: 23722

Connect your slider to an action method in your controller:

[theSlider addTarget:self 
              action:@selector(adjustSliderValue:) 
    forControlEvents:UIControlEventValueChanged];

Implement the slider action method:

- (void) adjustSliderValue: (UISlider *) slider
{
    // Change controller's state here. 
    // The next line will trigger -tableView:titleForFooterInSection:
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex: mySectionIndex] 
                  withRowAnimation:UITableViewRowAnimationNone];
}

This is more efficient than reloading the whole table. Unfortunately, there is no way to set a section footer text directly.

Upvotes: 4

Related Questions