load/refresh button in my custom web browser
So I'm building a custom web browser with a a lot of custom features, but I'm having a problem with something very simple. I have a NSTimer:
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkLoad) userInfo:nil repeats:YES];
and here is the method it calls:
-(void)checkLoad{
if (webView.loading) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
//add button to address bar
UIButton *stopButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
stopButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
[stopButton addTarget:self action:@selector(stop) forControlEvents:UIControlEventTouchUpInside];
addressBar.rightView = stopButton;
addres开发者_运维技巧sBar.rightViewMode = UITextFieldViewModeUnlessEditing;
}
else if (!(webView.loading)) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
//add button to address bar
UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
refreshButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
[refreshButton addTarget:self action:@selector(refresh) forControlEvents:UIControlEventTouchUpInside];
addressBar.rightView = refreshButton;
addressBar.rightViewMode = UITextFieldViewModeUnlessEditing;
}
}
the buttons show up just fine, and they change when the page is loading or not loading. but the interaction with them is very spastic. the refresh button works most of the time, but the stop button almost never works. I've played with the timing on the NSTimer making it longer and shorter to no avail.
also, I know the button images are wrong, but those are just placeholder's until I can get the refresh and stop loading images like the ones in safari.
any ideas? I am totally willing to do something completely different to detect when the page is loading (that would actually be preferred as I don't want an NSTimer looping every .2 seconds if I can avoid it but this was the only way I could find.
What's wrong with using the delegate methods of UIWebView
? See UIWebViewDelegate.
Setting up timers that fire every small fraction of a second so you can check something is a 'code smell'.
精彩评论