0

Part of my iOS app has a UIWebView that has a button bar on the bottom and loads a local index.html file. The 2 buttons on the bar are 'back' and 'done'. The index.html file is a list of downloaded (hence also local) html mini-apps which are loaded into that same webview. Because of some required navigation issues with those mini-apps the webview's 'back' button is not a goBack connected to the webView, it's really a link button back to the index.html.

I need that 'back' button to be hidden or disabled if index.html is the active page in the webview. I know how to disable it entirely, but I need it enabled when mini-apps are loaded to get back to the list. Any suggestions? Many thanks!

LeGaTTiS
  • 1
  • 3

1 Answers1

0

You can implement one UIWebView's delegate protocols:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

Then you could do something like this:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSString *currentURL = [[request URL] absoluteString];
if ([currentURL isEqualToString:@"index.html"]) {
//hide the bar button item
//something like: [button setHidden:YES];
}

else {
//something like: [button setHidden:NO];

}
return YES;
}
bobbypage
  • 2,157
  • 2
  • 21
  • 21
  • Sweet, thanks. Does this get added to my WebViewController or AppDelegate? – LeGaTTiS May 17 '11 at 01:12
  • Ok, I'm kinda noob at this. I'm having trouble getting this to work. This code should be pulling the current url, right? Also, the property setHidden didn't recognize so I'm using setEnabled but to no effect. – LeGaTTiS May 17 '11 at 01:19
  • add the code to your webview controlled. Remember to set the delegate of your web view e.g.: `webView.delegate=self` – bobbypage May 17 '11 at 01:36
  • added to the viewDidLoad? I'm still struggling with this, thought it seems clear. – LeGaTTiS May 17 '11 at 01:55
  • Yeah, I'm getting no errors but this isn't disabling or hiding the button if index.html is loaded. I've added this code to the webview controler, set the delegate, played with file names and used NSURL *url = [request URL]; NSString *urlString = [url absoluteString]; instead.....I even connected the webview delegate to file own in IB. I cannot get this button hid. Any guidance? – LeGaTTiS May 17 '11 at 03:06
  • perhaps I'm calling my button wrong? I have IBOutlet UIBarButtonItem *home; as well as - (IBAction) home:(id)sender; in my .h....hence the button is called home, right? so my IF statement should read something like [home setEnabled:NO];...right? – LeGaTTiS May 17 '11 at 03:11
  • Any guidance on how to make this code disable my bar button, which I believe is called 'home'? Or any other solutions? Is it in poor taste to offer to pay for a solution? – LeGaTTiS May 17 '11 at 17:16