如何在选择任何网站时在xcode的文本字段中加载URL?

时间:2014-09-09 09:47:14

标签: ios xcode uiwebview

我创建了一个应用程序,它是一个Web浏览器。每当我在文本字段中输入任何URL时,它都会转到所需的网页。我已经包含了一个UIWebView来显示网页。默认情况下,谷歌网站已打开。但是,当我从谷歌选择任何网站时,我想在文本字段中显示该URL。我该怎么做?

- (void)viewDidLoad
{
  [super viewDidLoad];

  self.myTextField.text = @"http://www.google.com";
  NSURL *myURL = [NSURL URLWithString:@"http://www.google.com"];
  NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
  [_myWebView loadRequest:myRequest];
  self.myTextField.delegate = self;
}

1 个答案:

答案 0 :(得分:2)

你可以这样做

 - (void)viewDidLoad
    {
      [super viewDidLoad];

      self.myTextField.text = @"http://www.google.com";
      NSURL *myURL = [NSURL URLWithString:@"http://www.google.com"];
      NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
      [_myWebView loadRequest:myRequest];
      _myWebView.delegate = self;
      self.myTextField.delegate = self;
    }

- (void)webViewDidFinishLoad:(UIWebView *)webView;
{
    NSURL *requestURL       = [webView.request URL];
    txtView.text   = [requestURL absoluteString];

}