UISearchBar

Forum for posting sample code and examples, new posts creation is not allowed, but everybody can comment

Re: UISearchBar

Postby sunny » Sun Jul 11, 2010 12:55 am

change textDidChange: method to this:
Code: Select all
- (void)searchBar:(UISearchBar *)searchBarControl textDidChange:(NSString *)searchText
{
   NSString *query = [_searchBar.text stringByReplacingOccurrencesOfString:@"\'" withString:@"\\\'"];
   [_webView performSelectorOnMainThread:@selector(stringByEvaluatingJavaScriptFromString:) withObject:[NSString stringWithFormat:@"searchUpdated('%@');", query] waitUntilDone:NO];
}

everything will work :)
User avatar
sunny
Staff
 
Posts: 1787
Joined: Sat May 30, 2009 5:18 am
Location: kiev, Ukraine

Re: UISearchBar

Postby nagrom » Tue Jul 13, 2010 2:02 pm

Thanks Sunny, that worked a treat. The UISearchbar now returns the correct text from the control and after I handle apostrophes in the html, the search results are perfect.

Thanks for your response.
nagrom
 
Posts: 4
Joined: Sat Jul 10, 2010 10:18 pm
Location: South Wales

Re: UISearchBar

Postby raf69 » Fri Jul 23, 2010 11:46 am

Hi everybody,

I use this sample project and it works great ! (thx Sunny) But... I've got a question... How do you manage the landscape view ? Indeed, when I rotate the device, the UISearch control doesn't fit with the WebView :( The search bar width is not auto resized.

I'm a noob in obj-c code so how can I fix this display bug ?

Thanks !
raf69
 
Posts: 15
Joined: Tue Jun 29, 2010 10:23 am

Re: UISearchBar

Postby sunny » Sat Jul 24, 2010 10:11 pm

I guess you need to set 'autoresizingmask' property
User avatar
sunny
Staff
 
Posts: 1787
Joined: Sat May 30, 2009 5:18 am
Location: kiev, Ukraine

Re: UISearchBar

Postby jezjones » Tue Aug 10, 2010 9:39 am

:D

Just wanted to say i got this into my project on 1.9.2 and working in about 5 minutes, Thanks Sunny and everyone who has posted extra stuff on here, getting the keyboard to open up immediately is just what i needed.

I changed (void)searchBarSearchButtonClicked function to get the field value to JS when you click search

Code: Select all
   [_webView performSelectorOnMainThread:@selector(stringByEvaluatingJavaScriptFromString:) withObject:[NSString stringWithFormat:@"searchButtonClicked('%@');", _searchBar.text] waitUntilDone:NO];
jezjones
 
Posts: 36
Joined: Thu Mar 11, 2010 3:12 pm

Previous

Return to Sample Code

Who is online

Users browsing this forum: No registered users and 1 guest