Question

I am working on an IPhone app and i have a UIWebview that by default loads a url.

I need to create a UIToolbar with three buttons under UIWebview which will allow users to hit the buttons and load a new url in UIWebview?

Était-ce utile?

La solution

you have to add three buttons to your toolbar( This can be easily done by using the Interface builder(IB) and connect them to there respective IBAction in the IB.

now when tap on a a button you can do like this.

you have a UIWebView say myWebView //declared in .h file and properly linked with the your View using IB.

when you are done with the basic initialization

for button1 press

   -(IBAction)button1:(id)sender
    {
          NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
          NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
          [myWebView loadRequest:requestObj];
    }

so by clicking on the button1 google webpage is loaded in your webView.

do the same for other button also. :)

Autres conseils

These methods and properties of UIWebview maybe help:

- (void)reload;
- (void)stopLoading;

- (void)goBack;
- (void)goForward;

@property(nonatomic,readonly,getter=canGoBack) BOOL canGoBack;
@property(nonatomic,readonly,getter=canGoForward) BOOL canGoForward;
@property(nonatomic,readonly,getter=isLoading) BOOL loading;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top