0

I am looking for a quicker method to build my application. As i have a series of buttons they all going to open a UIWebView. But each button is going to different website.

May I know is it possible that I just make one xib file? Or should I just create a new file for each of the button?

Here is my code for going to the next xib.

- (IBAction)items:(id)sender {

        //toggle the correct view to be visible
        Chelseapic *myView1 =[[Chelseapic alloc] initWithNibName:nil bundle:nil];
        [myView1 setModalTransitionStyle:UIModalTransitionStylePartialCurl];
        [self presentModalViewController:myView1 animated:YES];
    }

And this is the code for opening URL in the WebView xib.

- (void)viewDidLoad
{       
    [super viewDidLoad];
    NSString *urlAddress = @"http://www.google.com" ;
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
    [self.view addSubview:webView];

}

Many thanks

Vladimir
  • 170,431
  • 36
  • 387
  • 313
Clarence
  • 1,951
  • 2
  • 34
  • 49

1 Answers1

1

If you have a fixed set of buttons that you want to lay out in your nib, try making a separate IBAction for each button:

// helper method
- (void)presentViewControllerForURL:(NSURL *)url
{
    Chelseapic *vc = [[Chelseapic alloc] initWithNibName:nil bundle:nil];
    vc.url = url;
    [vc setModalTransitionStyle:UIModalTransitionStylePartialCurl];
    [self presentModalViewController:vc animated:YES];
}

// Connect the first button in your nib to this action.
- (IBAction)presentGoogle:(id)sender
{
    [self presentViewControllerForURL:[NSURL URLWithString:@"http://www.google.com/"]];
}

// Connect the second button in your nib to this action.
- (IBAction)presentStackOverflow:(id)sender
{
    [self presentViewControllerForURL:[NSURL URLWithString:@"http://stackoverflow.com/"]];
}

// etc.

You'll need to give Chelseapic a url property that it uses in viewDidLoad, instead of hardcoding the URL there.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848