views:

42

answers:

1

I have create a custom UIWebView. On some class if I include my custom UIWebView, I need know if web view load is complete or not. I can get this in custom class using webViewDidFinishLoad, but how do I transfer this to Main view where I have add this Custom UIWebView. I need to enable some button when WebView is loaded.

I hope u can understand. Thanks

+1  A: 

I think the good solution is to create a delegate pattern. You can pass the class (that include UIWebView) as a delegate, then when the UIWebView finish, you just need to call back that class to notify

In your custom UIWebView:

UIMyWebView.h:

@property (nonatomic, assign) id delegate;
@property (nonatomic, assign) SEL callback;

- (id)initWithDelegate:(id)delegate callback:(SEL)callback;

UIMyWebView.m:


- (id)initWithDelegate:(id)aDelegate callback:(SEL)aCallback {
  delegate = aDelegate;
  callback = aCallback;
}

- webViewDidFinishLoad {
  [delegate performSelector:callback];
}

YourCaller.m:

- finishLoading {
  // do something when finish loading
}

- myMethod {
  UIMyWebView *webView = [[UIMyWebView alloc] initWithDelegate:self callback:@selector(finishLoading)];
}
vodkhang
Thanks, but can u pleas let me know how to create delegate for this. It would be great if u provide some example. It will help me learn by this :)
iPhoneDev
ok, just changed the answer
vodkhang
Thanks a lot :)
iPhoneDev
One quick question, can we do the same thing using @protocol. Like using id <protocol> ... thanks in advance
iPhoneDev
You can do it using protocol and you don't need to pass the callback anymore:)
vodkhang