Which UIWebView has the load request?
So my class has two different UIWebView objects (one is a menu the other is for content). Let's call them UIWebView "A" and UIWebView "B"
In my shouldStartLoadWithRequest how do i determine which UIWebView a link was called from? Was it "A" or "B"? I thought i could just check a property like "title" or "name" so i looked through the documentation but no such luck.
I'm looking for something like this...
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"WebView is... %@",[webView title]);
}
If i log the entire webView i get a large hash but no reference to the original name i gave it in my IBOutlet. Hope this makes sense.
Also, could someone point me to how i would find 开发者_开发问答this kind of properties in the documentation because it seems like a pretty basic thing i am trying to do.
You can just test if the webView
parameter passed to that method is equal to the ivars you declared.
For example, if the ivars for the IBOutlets are named webViewA
and webViewB
:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (webView == webViewA)
NSLog(@"webview A wants to load %@", request);
else
if (webView == webViewB)
NSLog(@"webview B wants to load %@", request);
else
NSLog(@"some other webview wants to load %@", request);
return YES;
}
Alternatively, you can also set the tag
property of each web view either in IB or code to some non-zero values (say 10 and 20) and check the value of webView.tag
in the delegate method.
精彩评论