views:

27

answers:

1

I have a uiwebview embedded within a navigation controller. I would like the ability to change the uiwebview by simply clicking a uibarbuttonitem. anyone have any idea how to do that?

heres the method i have right now.

-(void)action {

    if (item.link) {
        self.linkString = item.link;
    }
    NSString *urlAddress = @"%@/#comments", linkString;

    NSURL *address = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:address];
    [contentLabel loadRequest:requestObj];
}
A: 

You could set the target selector or IBAction to change the request object:

  -(IBAction) action {
         NSString *urlAddress = @"http://google.com";

         NSURL *address = [NSURL URLWithString:urlAddress];
         NSURLRequest *requestObj = [NSURLRequest requestWithURL:address];
         [theWebView loadRequest:requestObj];
    }

or

  -(void) action {
         NSString *urlAddress = @"http://google.com";

         NSURL *address = [NSURL URLWithString:urlAddress];
         NSURLRequest *requestObj = [NSURLRequest requestWithURL:address];
         [theWebView loadRequest:requestObj];
    }
Kolin Krewinkel
ok that works perfectly. now what if i wanted to make the url change?like if i want it to have the same url as the webview but with /#comments tacked on at the end?
Colby Bookout
Do you mean go to a specific anchor?
Kolin Krewinkel
what i have right now isif (item.link) { self.linkString = item.link; } NSString *urlAddress = @"%@/#comments", linkString;but it doesnt like the NSString *urlAdd... line
Colby Bookout
view my edit of original post
Colby Bookout
NSString *anchor = @"#y-footer"; NSURL *footertag = [NSURL URLWithString:anchor]; NSURLRequest *scroll = [NSURLRequest requestWithURL:footertag]; [webView loadRequest:scroll];(I believe in a different selector this would work.)
Kolin Krewinkel
wait, so i need to make another method with that in it? and what is the #y-footer?
Colby Bookout
the first one you said worked. just had to add: NSString *urlAddress = [NSString stringWithFormat: @"%@/#comments", linkString];to it
Colby Bookout
Okay! I just had typed it in to the browser so I was a little unsure.
Kolin Krewinkel