Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-11-2011, 12:41 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 7
nagol2013 is on a distinguished road
Default Xcode problems

Hi, I am working on an application and part of it is to let the user type something in a text field and search it via google. Right now I have it linked to google and when the user presses search its transitions to the webView. My problem is that I can't get xcode to take what the user has typed into the text field and insert it into the google link properly. Right now it just shows a search of "(null)" in the webView. I was wondering if anyone can help me resolve this.

NSLog(@"%@",searchBarGoogle.text);
NSString *string1 = [[NSString alloc] initWithFormat:@"%@",searchBarGoogle.text];
NSString *string = [NSString stringWithFormat:@"http://www.google.com/search?q=%@",string1];
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];

Thanks in advance for future help!
nagol2013 is offline   Reply With Quote
Old 06-11-2011, 12:56 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

There's no need for string1, and you're leaking it as well. What's in the search filed? Are you sure URLWithString is returning you anything? It the string you pass it is not valid for an URL it will return nil. You should be checking the user input and escaping the characters that need to be escaped.
baja_yu is offline   Reply With Quote
Old 06-12-2011, 04:30 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 7
nagol2013 is on a distinguished road
Default

Why isnt this code working?



NSString *string = [searchBarGoogle.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com/search?q=%@", string]];
[NSString stringWithFormat:@"%d%%", 1];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
nagol2013 is offline   Reply With Quote
Old 06-12-2011, 04:33 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

1. Please use [code] tags around code when posting
2. The space character is not the only one that needs to be escaped. Check out stringByAddingPercentEscapesUsingEncoding method of NSString on how to do it properly.
3. What is this line supposed to do:

Code:
[NSString stringWithFormat:@"%d%%", 1];
4. Did you try to do some debugging to see why it doesn't work? For example print out the value of "url" (NSUrl object) to see if it gave you a valid object at all and so on.
baja_yu is offline   Reply With Quote
Old 06-12-2011, 04:49 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 7
nagol2013 is on a distinguished road
Default

that line is percent escaping the % i believe
nagol2013 is offline   Reply With Quote
Old 06-12-2011, 04:52 PM   #6 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

No it's not. Even if you read the return value it still isn't. But as is, it just creates an NSString object which just floats away as a helium filled balloon before eventually being popped.
baja_yu is offline   Reply With Quote
Reply

Bookmarks

Tags
google, problems, search bar, text field, xcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 318
6 members and 312 guests
chemistry, Dnnake, iOS.Lover, lendo, Leslie80, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:22 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0