Update viewForFooterInSection for delegate didSelectRowAtIndexPath

I show a list of items in a UITableViewCell in different sections. I created a UITextField in the delegate viewForFooterInSection

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

Now my problem is that I do not want to show viewForFooterInSection every time. It should be nil / hidden until I click doSelectRowAtIndexPath for this particular section. And UITextField should only show for this section.

I am confused how to reload footerView when clicked?

+4
source share
2 answers

You can reload the footer by simply reloading the section.

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

After this call - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section will hit again where you can save the boolean and return zero or footer accordingly.

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

NTN

Akshay

+6
source

The simplest answer is to simply call [tableView reloadData] . Although this does not give any animation, I cannot come up with any nominally simple way to support the animation in this case. This may be possible by inserting a line at the bottom of the section that looks like a footer, but this has to do with a whole host of other issues that I would not want to deal with.

Edit : just found an option that is slightly better:

[tableView reloadSections:withRowAnimation:] . I don't know if this will animate the footer or not, or it will even query your data provider, but it's worth it.

+1
source

All Articles