Do not know if there is anything else good way, recently in implementing a demand (click Search, then enter search content, show the results of the search, and then click on the search results, in the current page to display the results of the click of the detailed information). The problem is that when you click on the search results, the results of the search are not hidden, so you can't see what's blocking it.
The solution is
For (ID view in subviews) {
if ([View Iskindofclass:[uibutton class]]) {
UIButton *cancelbutton = (UIButton *) view;
[CancelButton settitle:@ "Cancel" forstate:uicontrolstatenormal];
Gets the response event that hits the "Cancel" button (Actionsfortarget This method returns an array)
self.cancelsearchselstring = [[CancelButton actionsfortarget:mysearchbar forcontrolevent: UIControlEventTouchUpInside] objectatindex:0];
Response notification, run the method directly with the response event method obtained above, conversion (this is a knowledge point, can be extended under)
[[Nsnotificationcenter Defaultcenter] Addobserver:mysearchbar selector:nsselectorfromstring ( self.cancelsearchselstring) name:@ "Cancelsearch" object:nil];
}
}
Then in the Click event
[[Nsnotificationcenter Defaultcenter] postnotificationname:@ "Cancelsearch" object:nil];
Announce---response---cancellation notice
[[Nsnotificationcenter Defaultcenter] Removeobserver:mysearchbar name:@ "Cancelsearch" object:nil];
On the line.
In iOS, the way to hide search results by clicking Search results.