开发者

How to implement google search application in iphone

开发者 https://www.devze.com 2023-03-14 06:39 出处:网络
I am new to iPhone development. I am making an application where I need to i开发者_如何学Gomplement Google Search application and display the results below...

I am new to iPhone development. I am making an application where I need to i开发者_如何学Gomplement Google Search application and display the results below...

Can anyone please help if there is any tutorial to implement this application. Is there any tutorial?

I think the code given below is right, if so then what else should be added to make it work?

Thank you

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];


in your .h file

#import <UIKit/UIKit.h>

@interface eddwedViewController : UIViewController {
    IBOutlet UITextField *searchtextField;

}
-(IBAction)search;

@end

In your .m file

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
        return YES;
}

-(IBAction)search
{
    NSString *searchString=searchtextField.text;    
    NSString *urlAddress = [NSString stringWithFormat:@"http://www.google.com/search?q=%@",searchString];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlAddress]];
}

In your view controller.xib make a textfield connect delegate with file owners and outlet with its name. Make a button and connect it action with search method.

Let me know if it is working for you.


try this:-

    NSString *searchString=@"apple";    
    NSString *urlAddress = [NSString stringWithFormat:@"http://www.google.com/search?q=%@",searchString];
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];

It is working fine.Hope It will help you.

what you can do is:-

NSString *searchString = searchBarGoogle.text;
0

精彩评论

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

关注公众号