Greg Cawthorne
Greg Cawthorne

Reputation: 416

How to respond to a touch in a UISearchBar and SearchDisplayController iPhone

I have followed this tutorial: http://blog.patrickcrosby.com/2010/04/27/iphone-ipad-uisearchbar-uisearchdisplaycontroller-asynchronous-example.html

In order to get my UISearchBar with SearchDisplayController. It works fine, but I don't know how make it so that when you press a suggestion from the drop down list UITableViewCells, it acts like an action and executes a method, where I can go something like:

NSString *Selected = [self SearchBar.selectedCell.text];

I am new to iPhone programming and sometimes find its quirks a tad confusing.

I have two view controllers and I'd ideally like to return the result you select from the searchDisplayController back to the initial ViewController, but just getting it to respond to a selection would be good. At the moment the cell just turns blue when you select it.

Here is my project so far: https://www.dropbox.com/s/m0zgookbwot05bo/Stocks%26Shares.zip

Click 'Search Companies' to see the UISearchBar and SearchDisplayController in its current state.

Any help would be great. If you need more info please just ask!

Upvotes: 0

Views: 289

Answers (1)

Dustin
Dustin

Reputation: 6803

In order to execute an action on table cell press you need to be implementing the UITableViewDelegate protocol in your class. Then use didSelectRowAtIndexPath to do your method. If you need to pass data between view controllers then look up the delegate pattern or, if your controllers are "close" enough to have a reference to each other then you can do [otherViewController someMethodThatDoesWhatYouWant].

Upvotes: 1

Related Questions