views:

29

answers:

1

I have one view holding a list of videos(buttons which can be clicked, each hold a url) which currently bring up a new view which holds the UIWebview, the only problem is I cant pass the url to the webview depending on which button was clicked.

At the moment I just get an empty UIWebview.

How can the url string be passed to the webview so it can load the correct url for each button?

Regards

+1  A: 
NSURL *videoURL = [NSURL URLWithString:@"http://..."];
[webView loadRequest:[NSURLRequest requestWithURL:videoURL]];

UPDATE:

In response to comment #3, here's what you can do:

  1. This goes without saying, but keep a reference to the UIWebView instance in Browser
  2. Add an NSString or NSURL @property to Browser
  3. Pass the URL to the Browser instance right after init
  4. In viewDidLoad:, call loadRequest:

So your code might look like this:

- (void)buttonClicked {
    Browser *browser = [[Browser alloc] initWithNibName:nil bundle:nil];
    browser.URL = [NSURL URLWithString:@"http..."];
    [self presentModalViewController:browser animated:YES];
    [browser release];
}

and in Browser's viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];
    [webView loadRequest:[NSURLRequest requestWithURL:URL]];
}
Can Berk Güder
I have code to load a url, but m not sure where to put it? If I put each url request in each button for the url needed, I cannot tie that to the webview? I would like to put the code in the viewdidload method of the webview, but am not sure how to give it the correct url from the button pressed.
alJaree
That depends on how you're loading the webview -- are you initializing it yourself? If so, extend the init function to include a new argument which is the URL.
Kalle
I have the following code to show the view holding the webview Browser *b = [[Browser alloc]initWithNibName:nil bundle:nil]; [self presentModalViewController:b animated:YES]; and I just have a UIWebview *browser in my Browser class which is link in IB. regards
alJaree
I solved it thanks. :) you were a great help. appreciate it.
alJaree
You're welcome.
Can Berk Güder