简体   繁体   中英

iOS: Activity Indicator and WebView

I have a scenario when the document takes time to download in a webview , user can press a cancel button provided in the activity indicator and can stop the downloading. I am using a different library for activity indicator. I need to know in webview that the button has been clicked in activity indicator or how can I have access to webview in activity indicator library. Can I set the activity indicator cancel button selector method in some other file? Quick help is much appreciated.

您可以使用“ Delegation或“ Notification来告知包含UIWebView的类在另一个类(“活动指示器”类)中已按下了“取消”按钮。

You can use NSNotificationCenter for get the Cancel button pressed event:

Add Observer

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(cancelButtonClicked:) name:@"cancelButton" object:nil];

Implement Cancel method

-(void)cancelButtonClicked:(NSNotification *)notification{
   // Do your action here
}

And also don't forget to remove observer once done with cancel:

[[NSNotificationCenter defaultCenter] removeObserver:self];

For detail check this one :

Send and receive messages through NSNotificationCenter in Objective-C?

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