reload section header when tapped on other section header

227 Views Asked by At

I have a UITableView with two sections in it. I have used custom views for the section headers and also added UITapGestureRecognisers on both of them.

I want to change the data on a section header when I tap on the other section header. How can I implement this ?

3

There are 3 best solutions below

0
On

One easy way to do it would be to add your customs section header views as instance variables on your view controller. That way you can easily reference them whenever a change happens.

0
On

The first thing that comes to mind is the fact that when you create a tap gesture recognizer, you assign a selector as so:

var tapGesture = UITapGestureRecognizer(target: <#AnyObject#>, action: <#Selector#>)

Why not just have both taps reference the same selector and update both section headers in the selector method if that is what you are looking for. Perhaps, I am not understanding your question fully though.

0
On

I assume that when the first section header is tapped you perform a selector to set the data you want to display in the second section header. The last thing your selector should do is call

self.tableView!.reloadData()

to redisplay the table. Only the displayed cells are redrawn so the call performs well.