Tariq
Tariq

Reputation: 9979

Refresh viewForFooterInSection on didSelectRowAtIndexPath delegate

I am showing list of items on UITableViewCell in different sections. I have created UITextField in viewForFooterInSection delegate

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

Now my problem is i dont want to show viewForFooterInSection everytime. It should be nil/hidden until i click didSelectRowAtIndexPath for that particular section. And UITextField should show only for that section only.

I am confused how to reload footerView on click ?

Upvotes: 5

Views: 10137

Answers (2)

Akshay
Akshay

Reputation: 5765

You can reload the footer view simply by reloading the section.

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationNone];

After this call, - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section hits again, where you can keep a boolean variable and accordingly return nil or your footer view.

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if(conditionSatisfied)
        return myFooterView;
    return nil;
}

HTH,

Akshay

Upvotes: 7

Ed Marty
Ed Marty

Reputation: 39700

The simplest answer is simply to call [tableView reloadData]. Although this doesn't supply any sort of animation, I can't think of any nominally easy way to support animation in this case. It may be possible by inserting a row at the bottom of the section that looks like the footer, but that comes with another whole host of issues that I wouldn't want to deal with.

Edit: Just found a possibly slightly better option:

[tableView reloadSections:withRowAnimation:]. I've no idea whether this will animate the footer or not, or whether it will even make the query to your data provider, but it's worth a shot.

Upvotes: 1

Related Questions