0

I have a scenario, where I am waiting for a uiwebview to get fully loaded and then a delegate called from finishedWebViewLoading once completed. However, I want to return that webView when finished loading as an object which is a private object to another Class. Is there anyway to do that through delegates? I don't want to have that uiwebview as a public property, hence I have utilized it under my main file.

Thanks.

topgun
  • 2,463
  • 8
  • 31
  • 46

4 Answers4

2

sure you can do it like this .. in .h

@protocol yourClassProtocal <NSObject>

- (void) loadingFinsihForWebView:(UIWebView*)wv;

@end

and in the webView Delegate webViewDidFinishLoad

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [delegate loadingFinsihForWebView:webView];
}
Malek_Jundi
  • 6,140
  • 2
  • 27
  • 36
0

The answer to your question is: YES. However, I believe you might need to read up on how delegates work and how to create them, this post might get you on the right path getting there: How does a delegate work in objective-C?

Also, have a look at this article: http://blog.shoguniphicus.com/2011/10/17/writing-custom-delegate-in-objective-c/

Community
  • 1
  • 1
Paul Peelen
  • 10,073
  • 15
  • 85
  • 168
0

You can use this:

 if([self.theDelegate respondsToSelector:@selector(loadData:)]) {
        [self.theDelegate performSelector:@selector(loadData:) withObject:theObject]; 
Luke
  • 11,426
  • 43
  • 60
  • 69
Saad
  • 8,857
  • 2
  • 41
  • 51
0

I am not sure I understand what you are asking, but you cannot return any value from (void)webViewDidFinishLoad:(UIWebView*)webView, nor can you change the delegate signature.

On the other hand, if you mean that you are going to call another custom delegate method from webViewDidFinishLoad, and that you want that it returns the webView, then this is definitely possible. Simply call that custom delegate method and pass the webView to it, then make the custom delegate method return it.

This assumes you are in charge of the definition of the custom delegate method signature, e.g.:

@protocol CustomDelegateProtocol
    - (UIWebView*)myCustomDelegateMethod:(UIWebView*)view;
@end
sergio
  • 68,819
  • 11
  • 102
  • 123