UISearchBar

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

Re: UISearchBar

Postby sunny » Fri May 07, 2010 5:45 pm

that should be very easy, send some sample of your implementation and I'll add keyboard hide on clearing to it as I guess not everybody would like to have this kind of thing as default in sample code
User avatar
sunny
Staff
 
Posts: 1787
Joined: Sat May 30, 2009 5:18 am
Location: kiev, Ukraine

Re: UISearchBar

Postby BUXjr » Fri May 07, 2010 7:21 pm

Hey Sunny,

Thanks for getting back to me so quickly!

I am more than happy to send you whatever you might need in the way of a "sample", but I am not sure what you need...? I am using the MyUISearchBar.h & MyUISearchBar.m that are included in the .ZIP file -- with no changes (other than the prompt and placeholder). I just dropped 'em into my Classes subfolder and reference them on my form with:

Code: Select all
      NKRegisterClass("MyUISearchBar");
      CallNKitAction("showSearchBar?className=MyUISearchBar");   


Also included on the page are:

Code: Select all
      function searchUpdated(searchValue) {
         doSearch(searchValue);
      };
      
      function searchButtonClicked()
      {
         CallNKitAction("dismissKeyboard?className=MyUISearchBar");
      };


Ideally, I would like to have it extended to include a:

Code: Select all
      
      function clearFieldButtonClicked()
      {
         CallNKitAction("dismissKeyboard?className=MyUISearchBar");
      };


This way it could either be included or excluded as makes sense for the usage.

Do you need me to send you the .M and .H files? I should think you already have them...

LMK, I am happy to assist. I am just really lame in ObjC. Thanks, in advance.
Regards,

BUXjr
User avatar
BUXjr
 
Posts: 38
Joined: Thu May 06, 2010 6:03 am
Location: Austin, Texas, USA

Re: UISearchBar

Postby BUXjr » Sun May 09, 2010 8:19 am

Hey Sunny,

Any luck with this? I know this is a small request in comparison to the iPad deployment issues being reported on 1.8.3, but when you have a free second, could you please circle back around on this? Or anyone who has the chops...


BUMP

TIA
Regards,

BUXjr
User avatar
BUXjr
 
Posts: 38
Joined: Thu May 06, 2010 6:03 am
Location: Austin, Texas, USA

Re: UISearchBar

Postby BUXjr » Fri May 14, 2010 3:32 pm

Was this not doable, sunny?
Regards,

BUXjr
User avatar
BUXjr
 
Posts: 38
Joined: Thu May 06, 2010 6:03 am
Location: Austin, Texas, USA

Re: UISearchBar

Postby sunny » Fri May 14, 2010 3:56 pm

so what you usually do for this is following:
in method showSearchBar you insert _searchBar.showsCancelButton = YES;
and add one more method:
Code: Select all
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
   [self dismissKeyboard];
}

but this is not exactly what you want to have, you see there is no event fired when that small button clicked, so all you can do is check if it's empty on text editing and hide keyboard, to do so you need to insert this code:
Code: Select all
if (searchValue.length==0) CallNKitAction("dismissKeyboard?className=MyUISearchBar");
in the searchUpdated function, so the code from the example looks like this:
Code: Select all
   function searchUpdated(searchValue) {
      $("#container").html(searchValue);
      if (searchValue.length==0) CallNKitAction("dismissKeyboard?className=MyUISearchBar");
   }
User avatar
sunny
Staff
 
Posts: 1787
Joined: Sat May 30, 2009 5:18 am
Location: kiev, Ukraine

Re: UISearchBar

Postby BUXjr » Fri May 14, 2010 4:36 pm

Thanks, sunny!

Yeah, I was afraid of that. Ya see, if I do that on "textDidChange", then when the user uses the backspace/delete key to back out their previous input and start new input, the keyboard will disappear when they delete the last character -- which is not what I want. I really only want that keyboard to disappear if and only if they click the "clear out entire entry" button on the right end of the search bar entry field.

But, if there is NO event fired when they click that button, it will be impossible I suppose. Are you sure there is no event fired? Seems to me that there would be. I mean, how does the native control know to clear out the whole field as opposed to just one character...? So, there really is no, "searchBarCancelButtonClicked" on that control?

Sorry to beat a dead horse, but this noobie is very confused. Seems like it should be simple...

TIA
Regards,

BUXjr
User avatar
BUXjr
 
Posts: 38
Joined: Thu May 06, 2010 6:03 am
Location: Austin, Texas, USA

Re: UISearchBar

Postby sunny » Fri May 14, 2010 5:03 pm

probably somehow it's possible to get that event, but I don't see a legal way of doing this.
search bar is a view's subclass with it's additional methods and events which are accessible, but it also includes textfield which is a subview of search bar and we don't have access to it.
Ofc it's possible to obtain textfield and set our own delegate to it, but this is very bad idea and with iPhone OS update your application may start to crash, etc, really not recommended, better to have it on ontextchange
User avatar
sunny
Staff
 
Posts: 1787
Joined: Sat May 30, 2009 5:18 am
Location: kiev, Ukraine

Re: UISearchBar

Postby BUXjr » Fri May 14, 2010 6:08 pm

Understood. Wilco. While I certainly don't like the default behavior, it is not a deal-breaker. I can live with it. Maybe someday, down the line...

Thanks for the advice and your time, sunny. As usual, your attention to support is outstanding.

Велике спасибі!
Regards,

BUXjr
User avatar
BUXjr
 
Posts: 38
Joined: Thu May 06, 2010 6:03 am
Location: Austin, Texas, USA

Re: UISearchBar

Postby sluggish » Mon Jul 05, 2010 11:04 pm

this Sample Project works on NK 1.9?

i try it but i can't make it works sucesfull.

i donwloaded the Sample Project, added the classes to my project, and this code:
Code: Select all
<html>
<head>
<meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script src="jquery.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="NKit.js"></script>

<script>
   NKRegisterClass("MyUISearchBar");
   CallNKitAction("showSearchBar?className=MyUISearchBar");   
</script>
</head>
<body style="margin-top:75px">

<script>


var navBar = new NKNavigationController();
navBar.setTintColor(0, 136, 204);
navBar.setTitle("Buscar");

function searchUpdated(searchValue) {
      $("#container").html(searchValue);
   }
   function searchButtonClicked()
   {
      CallNKitAction("dismissKeyboard?className=MyUISearchBar");
   }
</script>



<div id="container">&emsp;&emsp;&emsp;Busca el artículo que desees.</div>


</body>
</html>


any ideas?
sluggish
NimbleKit Expert
 
Posts: 74
Joined: Fri Jan 08, 2010 4:18 am
Location: Madrid / Spain

Re: UISearchBar

Postby nagrom » Sat Jul 10, 2010 10:45 pm

Hello everyone, I wonder if anyone could help a noob to handle apostrophes (single quotes) in search strings using UISearchbar?

I have a DB of Names which may include o'toole, o'connor etc. The searchText breaks out after the single quote. I tried a javascript replace at the web page level mySearchText.replace("'","''"), but the searchText from the UISearchbar is truncated before being sent to the page ie. 'Des O'Connor' returns 'Des O'.

Forgive me if I have missed a post or I'm being a muppet, but I did search and couldn't find anything.
nagrom
 
Posts: 4
Joined: Sat Jul 10, 2010 10:18 pm
Location: South Wales

PreviousNext

Return to Sample Code

Who is online

Users browsing this forum: No registered users and 1 guest