Having a UITextField Changes the Web View URL

I have a viewcontroller with an xib file. The file must have a TextField and a button that leads to another viewcontroller with a web view. I want the url to be changed no matter what the user types in the text box. For example:

WebView URL: http://www.google.com/ user enters football into the text box . New URL in WebView: http://www.google.com/football

Any help would be really appreciated. I already have my “homepage” leading to web browsing. I just need to know what code should go, this is to change the URL.

Thanks in advance. If you need code, I can publish it

+3
source share
2

, -. :

NSString *stringToPass = [NSString stringWithFormat:@"www.google.com/%@", self.textField.text];

init, :

self.viewController = [ViewController alloc]initWithAddress:stringToPass];

-(id)initWithAddress:(NSString*)address; .h.

+2

@CodaFi...

// WebViewController.m

@property (strong, nonatomic) NSURL *url;
@property (weak, nonatomic) UIWebView *webView;

//@synthesize, etc.

-(id)initWithAddress:(NSString*)address {

    self = [super init];
    if (self) {
        self.url = [NSURL urlWithString:address];
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

    NSURLRequest *request = [NSURLRequest requestWithURL:self.url];
    [self.webView loadRequest:request];
}
0

All Articles