Varias preguntas de UIWebViews

I'm really not good with these protocols, especially because this is really my first time using them. I have two UIWebViews in the same view: webView and webView2. How do I change this line of code to work for webView2?

-(void)webViewDidStartLoad:(UIWebView *)webView {

I tried changing "webView" to "webView2", but Xcode said that I had the same line twice, so obviously this won't work. What should I do? Thanks for your help!

Btw, I'm thinking I have to add an IF statement within here, but what should it be?

preguntado el 28 de agosto de 11 a las 00:08

3 Respuestas

The delegate method passes in a parameter defining which web view it’s coming from for exactly this reason.

- (void)webViewDidStartLoad:(UIWebView *)theWebView
{
    if(theWebView == webView)
    {
        // do something
    } else if(theWebView == webView2)
    {
        // do something else
    }
}

Respondido 28 ago 11, 04:08

Well the same method will be called, but the ref of the webview is passed in, So you can keep a reference to both your webviews in your delegate and say something like if(webview1==webview) which will evaluate to yes only if the webview ref passed in the delegate method is webview1 so you can figure out which webview is calling the delegate using the if statement

Respondido 28 ago 11, 04:08

Creo que quieres:

- (void)webViewDidStartLoad:(UIWebView *)webView; {
  if(webView == webView1){
    // use the first webview here.
  }
  if(webView == webView2){
    // use the second webview here.
  }
}

¡Espero que ayude!

Respondido 28 ago 11, 04:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.