开发者

Update UITableView titleForFooterInSection for UISlider's valueChanged?

开发者 https://www.devze.com 2022-12-17 23:15 出处:网络
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.

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 wo开发者_运维百科rk 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..


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号