I’m making an iPad browser, and I have a little problem. When I go to google, for example, I write the google direction in a textField. The problem is that when I change the web page, it still says http://www.google.com/. Here’s my code:
-(IBAction)buttonpressed2:(id)sender {
url = [NSURL URLWithString:[textField text]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[webView isEqual:textField.text];
}
How can I make the textField show the page that I’m watching right now, and not the first url typed in the field?
First, make sure when you set up the webView, you assign the
UIWebViewDelegatetoselfThen, implement the delegate method:
webViewDidFinishLoad, as such:Edit:
A delegate is a special set of methods that wait for an event to happen. When that event happens, the appropiate method is called. The method above is one of the delegate methods for a
UIWebView– When a specific event happens with the webView, in this case when thewebViewDidFinishLoad, that method is automtically called and we can respond as such. In order to set the delegate, we can proceed one of two ways:If you created the webView in code, this is with something like this:
then all you need to do is add the following line of code:
However, you might have also created the webView in the interface builder – If that’s the case, click on the webView and the linker tab, and drag the delegate option over to “File’s Owner”.
and thats it.