KennC.
KennC.

Reputation: 3445

How to hide/show button based on website changes in UIWEBVIEW

hii, my iphone app loads a UIWEBVIEW website.

i load a login page intially and my javascript will check if the login is success b4 bring him to another webpage.

I have buttons on the toolbar which will call the javascript function, however, these button is only useful after the user has login, and not useful at all at the login page.

How do i code such as, only when the website changes, only that the button appears, so as not to mislead users? Thanks

Upvotes: 1

Views: 478

Answers (1)

Satya
Satya

Reputation: 3330

For this you have to implement webview delegate methods. There is a method named

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSURL *url = [request URL];
    NSString *urlString = [url absoluteString];

// Here I am getting the url values as "mob:Camera", "mob:Lib" So splitting the string and finding whether the second one is Camera or not


    NSArray *splitArray = [urlString componentsSeparatedByString:@":"];

if(![[splitArray objectAtIndex:0] isEqualToString:@"mob"])
    return YES;

if([[splitArray lastObject] isEqualToString:@"Camera"]){
    // Do what ever you want
    [webView stringByEvaluatingJavaScriptFromString:@"alert('Camera Clicked')"];
    }
}

in this method I have checked whether the string consists camera or not. Similarly check whether the user logged in or not.

Hint: by checking the user id in the url.

if you found then the user logged in, then you can show the toolbar.

Then the problem will be solved.

Regards,

Satya

Upvotes: 1

Related Questions