How to trigger cancel button in UISearchBar?

ios, iphone, uisearchbar

Solution

For a view controller using a search display controller, you can set

self.searchDisplayController.active = NO;
// or:
[self.searchDisplayController setActive:NO animated:YES];

to dismiss the search interface.

Problem

How to trigger programmatically cancel button in UISearchBar, like if you have tapped cancel button? I have a UISearchBar in the top of a UITableView and after a search, when someone select a row, I want to trigger programmatically cancel button in the UISearchBar? EDIT: Without user interaction.

Original source