我想要一个谷歌搜索栏。我创建了一个文本字段和一个搜索按钮,并尝试将其与搜索方法链接,但它不起作用。请帮助,因为我是 iOS 开发领域的新手。谢谢你。
这是“ViewController.m”
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor= [UIColor cyanColor];
searchtext = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 200, 40)];
searchtext.delegate = self;
searchtext.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:searchtext];
search = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[search setTitle:@"Search" forState:UIControlStateNormal];
[search setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
search.frame = CGRectMake(210, 0, 100, 30);
[self.view addSubview:search];
[search addTarget:self action:@selector(gotogooglesearch) forControlEvents:UIControlEventTouchUpInside];
-(void)gotogooglesearch{
NSMutableString *googleUrl = [[NSMutableString alloc] initWithString:@"http//www.google.com/search?q="];
NSString * searchString = [searchtext text];
[googleUrl appendString:searchString];
NSURL *url = [NSURL URLWithString:googleUrl];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end