iphoneios4uiwebviewuitoolbaruitoolbaritem

How to program UItoolbar buttons to load a new website in UIWebView?


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?


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. :)