简体   繁体   中英

How to set notification in iPhone

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

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)];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM