Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I created a simple webview that loads a pre-defined website in iOS app.

   NSURL *url =[NSURL URLWithString:@"http://jihadkawas.com"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[Webview loadRequest:req];

how can i add a URL BAR, so that user can access any url? like normal browsers? Thank you!

share|improve this question
add comment

2 Answers

You need to have a Textfield (the URL-Bar where Users can type in the website's address.

UITextField *urlBarTextField = [[UITextField alloc] initWithFrame:CGRectMake(0,0,320,40)];
[self.view addSubview:urlBarTextField];

And you need a go button or wait until the user pressed return on the Keyboard. In the called method (either the Button target method or -(void)textField: shouldReturn:)

You need to load the new URL and display it in the UIWebView

NSURL *url = [NSURL URLWithString:urlBarTextField.text];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];

That's it ;)

share|improve this answer
 
where should i write the first and the second code? in the .h or .m file? –  user2483669 Jun 15 '13 at 18:34
 
This is all implementation so .m. I would recommend you to read some raywenderlich basic iOS Tutorials. Then this will be totally clear to you –  lukaswelte Jun 15 '13 at 19:42
add comment

Just create a text field and a go button,

when the url presses the go button---

NSURL *url=[NSURL URLWithString:textField.text];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[Webview loadRequest:req];

There you go

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.