Help making a Unified address bar in ios 5 for a Browser App? So here is my address bar.
-(IBAction)url:(id)sender {
NSString *query = [urlBar.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSURL *urlQuery = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:urlQuery];
[webPage loadRequest:request];
}
Couldn’t I add an “else” reference to say if it is not an address then append the google search tag? If so how? And would you know how to use Bing instead of google?
-(IBAction)googleSearch:(id)sender {
NSString *query = [googleSearch.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSURL *urlQuery = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com/search?hl=en&site=&q=%@", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:urlQuery];
[webPage loadRequest:request];
}
Here are some tips to help you:
stringByAddingPercentEscapesUsingEncoding:instead of your “+” replacement.UIWebViewDelegateprotocol to identify when an error occurs when loading an invalid URLYour code should looks something as follow: