Enable/Disable button using webViewDidFinishLoad

2019-09-15 02:50发布

问题:

I'm working on an iOS app, and I need to prevent a UIButton from being usable until the page has finished loading (it uses resources that might not be on the page until it has loaded completely).

Right now, I've disabled the button in Interface Builder and am trying to use setEnabled in the webViewDidFinishLoad function. Here's what it looks like:

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [activityIndicator stopAnimating];

 [randomButton setEnabled:YES];

}

The activityIndicator stops animating and hides as expected, so I know the page is loading fully. However, the button remains disabled.

How can I enable that button after the webView finishes loading?

回答1:

Are you sure you've hooked up the 'randomButton' variable to the actual button in your .xib file?