سؤال

Two questions for today!

In my search app I start off in the search method with this line:

    myQuery = [searchBar.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

And then I move onto the rest of the method. The issue is for some reason it won't let me make searches of multiple words on either the simulator or an actual iPhone.

So if I write it like this:

myQuery = searchBar.text;
    [myQuery stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

It'll allow for multiple word searches, but on the real iPhone the string becomes null, somehow. On the simulator it works fine, but on the real phone it doesn't.

So first question is can anyone see something wrong here? Secondly, is there a much better way to do this?

هل كانت مفيدة؟

المحلول

It's null because you do not assign the returned string. Apart from that the two code fragments are really the same thing (by the way, how are you trying to 'search'? Are you sending this as a request to some server for example?). Try this one:

theQuery = searchBar.text;
myQuery = [theQuery stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top