Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 895
Tariq Avatar asked Aug 10 '11 13:08

Tariq


2 Answers

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

like image 50
Akshay Avatar answered Sep 20 '22 11:09

Akshay


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.

like image 38
Ed Marty Avatar answered Sep 22 '22 11:09

Ed Marty