开发者

problem certainly merge a space on the searchbar

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜