开发者

problem certainly merge a space on the searchbar

开发者 https://www.devze.com 2023-02-17 15:00 出处:网络
I have a problem implementing a searchbar. It works correctly as long as the string to search does not have any space, but if I introduce a search string with a space, it shows me an error.

I have a problem implementing a searchbar. It works correctly as long as the string to search does not have any space, but if I introduce a search string with a space, it shows me an error.

- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar {

      //[self searchTableView];

    if([searchBar.text length] > 0) {


        [stories removeAllObjects];
        NSLog(@"reset stories");


        if ([stories count] == 0) {

        NSString * path = [NSString stringWithFormat:@"http://buscador.main.conacyt.mx/search?q=%@&num=%d", searchBar.text,100];
        [self parseXMLFileAtURL:path];

        //Once the qu开发者_JAVA百科ery is complete, go load the view controller to show the data.
        [self performSelectorOnMainThread:@selector(showAsuntosResult) withObject:nil waitUntilDone:NO];
        }


The problem is not with your search bar itself, it's with what you're doing with the result.

You're using the search bar text to create a URL. URL's may not contain spaces.

To use a string containing spaces in a URL, you need to %-escape it, by doing something like:

path = [path stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号