我有一个链接到UIView的地址栏(textfiled)。我想说如果我在地址栏中输入"google"并按搜索(UIButton),那么"http"和"com"将动态添加到地址栏中。现在写我正在用我的代码传递"http"和"com",但我希望当用户单击 Seacrh(UIButton) 时在运行时自动生成这些东西。请告诉我该怎么做。我在下面发布我的代码:-
- (IBAction)search:(id)sender {
NSLog(@"hi");
NSString *http= @"http://";
addressbar.text=[NSString stringWithFormat:@"%@%@%@",http,addressbar.text,@".com"];
NSURL *url = [[NSURL alloc] initWithString:addressbar.text];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
self.web.scalesPageToFit = YES;
[self.web loadRequest:request];
}
试试这个:
- (IBAction)search:(id)sender {
NSLog(@"hi");
NSString *http= @"http://";
NSString *com= @".com";
NSURL *url = [NSString stringWithFormat:@"%@%@%@",http,addressbar.text,com];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
self.web.scalesPageToFit = YES;
[self.web loadRequest:request];
addressbar.text=url;
}