Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 16, 2009, 09:01 PM   #1
Programmer
macrumors member
 
Join Date: Jun 2009
Google Search Bar in Browser

could someone please help me figure out how to put a google search bar in the web browser I'm making in xcode.

Last edited by Programmer; Jun 18, 2009 at 04:11 PM.
Programmer is offline   0 Reply With Quote
Old Jun 16, 2009, 09:04 PM   #2
Nukemkb
macrumors 6502a
 
Nukemkb's Avatar
 
Join Date: Mar 2006
Location: Columbia, SC
hmm. select View, then 'customize toolbar', then drag it and drop it....
__________________
Live simply so that others may simply live... -Gandhi
Nukemkb is offline   0 Reply With Quote
Old Jun 16, 2009, 09:05 PM   #3
veterator
macrumors member
 
Join Date: Jan 2007
Location: Oklahoma
You are using Safari, right?
__________________
15" MacBook Pro 8GB/1TB; 13" MacBook Air i7, 1.8 Ghz; 32GB Black iPhone 4 ; iPad 2 BK/64GB/WiFi
veterator is offline   0 Reply With Quote
Old Jun 16, 2009, 09:06 PM   #4
Nukemkb
macrumors 6502a
 
Nukemkb's Avatar
 
Join Date: Mar 2006
Location: Columbia, SC
Quote:
Originally Posted by veterator View Post
You are using Safari, right?
Good question!
__________________
Live simply so that others may simply live... -Gandhi
Nukemkb is offline   0 Reply With Quote
Old Jun 18, 2009, 04:10 PM   #5
Programmer
Thread Starter
macrumors member
 
Join Date: Jun 2009
xcode

no i'm i am trying to program it into my web browser i'm making in xcode.
Programmer is offline   0 Reply With Quote
Old Jun 18, 2009, 07:00 PM   #6
Thomas Harte
macrumors 6502
 
Join Date: Nov 2005
Quote:
Originally Posted by Programmer View Post
no i'm i am trying to program it into my web browser i'm making in xcode.
How do you currently have your webView set up to get page URLs? Do you have it connected to an NSTextField via takeStringURLFrom: or are you pushing URLs to it with setMainFrameURL:?

In either case, you'll want to set yourself up as a delegate of a second NSTextField, do something like this when you receive textDidEndEditing: from it:

Code:
NSString *searchURL = [NSString stringWithFormat:@"http://www.google.com/search?q=%@", [googleField stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Then set searchURL to your normal URL bar, possibly passing it to the WebView as well if you have the link between the two going through your own code.

The main observations are merely that you need to:

(i) escape the search string (eg, to turn a space into %20 so that it works in a URL); and
(ii) add http://www.google.com/search?q= to the start to turn it into a Google search URL.

Then just treat that identically to a URL directly entered by the user.
Thomas Harte is offline   0 Reply With Quote
Old Jun 18, 2009, 07:41 PM   #7
Programmer
Thread Starter
macrumors member
 
Join Date: Jun 2009
Thanks

thanks
what i'v been having trouble with is when i try to retrieve the text from the google search bar in the .h file then do the @synthesize in the .m file to put it into this string of code

[HTML]NSString *searchURL = [NSString stringWithFormat:@"http://www.google.com/search?q=%@", [GoogleSearchField stringValue]];[/HTML]

i am used to programing on the iphone this is what i would normally do so i don't know if it is different on a mac
Programmer is offline   0 Reply With Quote
Old Jul 9, 2009, 10:01 PM   #8
Programmer
Thread Starter
macrumors member
 
Join Date: Jun 2009
url field problem

i'm making a web browser but when i run this code

- (BOOL)textFieldShouldReturnUITextField *)textField
{
NSString *searchURL = [NSString stringWithFormat:@"http://", [urlField stringValue], NSString stringWithFormat:@".com"];
[textField resignFirstResponder];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[textField text]]]];


return YES;
}

i get this

[HTML]Expected expression before NSString[/HTML]

can anyone help
Programmer is offline   0 Reply With Quote
Old Jul 9, 2009, 10:43 PM   #9
dejo
Demi-God (Moderator)
 
dejo's Avatar
 
Join Date: Sep 2004
Location: Colorado
First (and we really need to sticky this for this forum), if you're going to include cope snippets, please enclose them in [ CODE ][ /CODE ] tags (spaces removed). These tags are easily accessed via the # icon in the toolbar.

Second, your problem starts here:
Code:
- (BOOL)textFieldShouldReturnUITextField *)textField
You probably want something like this instead:
Code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
...and continues here:
Code:
NSString *searchURL = [NSString stringWithFormat:@"http://", [urlField stringValue], NSString stringWithFormat:@".com"];
You probably want something like this:
Code:
NSString *searchURL = [NSString stringWithFormat:@"http://%@%@", [textField text], @".com"];
__________________
My iOS Apps: a.k.a., DreamStream
I support the MacRumors Blood Drive!
dejo is offline   0 Reply With Quote
Old Jul 10, 2009, 12:19 PM   #10
autorelease
macrumors regular
 
Join Date: Oct 2008
Location: Achewood, CA
Quote:
Originally Posted by Programmer View Post
NSString *searchURL = [NSString stringWithFormat:@"http://", [urlField stringValue], NSString stringWithFormat:@".com"]
Learn about strings. That line is nonsense.

What you want is

Code:
NSString *searchURL = [NSString stringWithFormat:@"http://%@.com", [urlField stringValue]]
__________________
*** -[NSAutoreleasePool autorelease]: Cannot autorelease an autorelease pool
autorelease is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Google search bar in safari nalk7 iPad 6 Sep 1, 2010 01:30 PM
Google search suggestions in Search Bar tejaykay iPhone Tips, Help and Troubleshooting 0 Jul 28, 2010 10:42 AM
Safari google search bar how to change to uk searches chipandegg Mac OS X 1 May 23, 2009 02:30 AM
Clearing Google search bar in Safari 4? Learjet035 Mac Applications and Mac App Store 1 Mar 4, 2009 05:48 PM
Safari - Text fill in Google Search Bar? meagain Mac OS X 0 Jul 2, 2007 10:59 PM


All times are GMT -5. The time now is 06:54 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC