Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Make an action when searchBar cancel button is tapped

I have a tableView with a searchBar. I want to reload my tableView data when the searchBar cancel Button is tapped.

func searchBarCancelButtonClicked(searchBar: UISearchBar) { println("cancel button tapped")

self.tableView.reloadData()

} i set :

UISearchBarDelegate and :

 override func viewDidLoad() {

self.searchBar.delegate = self

} What is weird is that searchBarSearchButtonClicked is working good.

What did i miss ?

1 Answer

if you call the reloadData method of the tableView, it only reloads the data that is available in the current datasource.

You should also change/reload your datasource in order to get some changes in your tableView.

Ok thanks but in fact this is the function itself witch isn't called. My println isn't working.