我是iPhone开发的新手。 我正在制作一个应用程序,我需要实现Google搜索应用程序并显示以下结果...
如果有任何教程来实现此应用程序,任何人都可以请帮助。 有没有教程? 我认为下面给出的代码是正确的,如果是这样,那么应该添加什么才能使它工作?
谢谢
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];I am new to iPhone development. I am making an application where I need to implement 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];最满意答案
在你的.h文件中
#import <UIKit/UIKit.h> @interface eddwedViewController : UIViewController { IBOutlet UITextField *searchtextField; } -(IBAction)search; @end在.m文件中
- (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]]; }在您的视图中,controller.xib将文本字段连接委托与文件所有者和出口及其名称。 创建一个按钮并将其与搜索方法连接起来。
如果它适合您,请告诉我。
in your .h file
#import <UIKit/UIKit.h> @interface eddwedViewController : UIViewController { IBOutlet UITextField *searchtextField; } -(IBAction)search; @endIn 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.
更多推荐
发布评论