views:

391

answers:

1

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..

+1  A: 

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.

Costique
That doesn't work. It's the same issue as described in this post: http://stackoverflow.com/questions/1252781/uislider-update-inside-uitableviewcell -- I can update the cell's textLabel, but updating the section or tableView to update the footer does not work.
Canada Dev
Ah, I see it now. OK, it looks like you have to implement -tableView:viewForFooterInSection: instead. That way the view is completely under your control and you can interact with it directly, without reloading data. To avoid memory-related issues while scrolling make it a retained ivar in your controller. The view may be of any UIView subclass, including UILabel.
Costique
Ah, you're right. Hey if you can write that as an answer I'll mark it as the correct answer so you get points or whatever :)
Canada Dev