dismissing uiwebview

Posted by chimgrrl on Stack Overflow See other posts from Stack Overflow or by chimgrrl
Published on 2010-06-18T04:13:48Z Indexed on 2010/06/18 4:23 UTC
Read the original article Hit count: 153

Filed under:
|
|

Ok, I really spend 2 days on this and it has gotten me stumped.

From my main UIViewController I called a WebViewController which is a UIViewController with a UIWebView inside:

UOLCategoriesWebViewController *ucwvcontroller = [[UOLCategoriesWebViewController alloc] initWithNibName:@"UOLCategoriesWebViewController" bundle:nil];

    [self presentModalViewController:ucwvcontroller animated:YES];
    [ucwvcontroller release];

Inside the UOLCategoriesWebViewController I've call the delegate method shouldStartLoadWithRequest where when the user clicks on a particular type of link it parses out the params and return back to the main UIViewController (or at least that's what I want it to do):

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    BOOL continueOrExit = YES;
    NSURL *url = request.URL;
    NSString *urlString = [url relativeString];
    NSString *urlParams = [url query];
    NSArray *urlParamArr = [urlParams componentsSeparatedByString:@"&"];
    NSLog(@"the url is: %@",urlString);
    //NSLog(@"the params are: %@,%@",[urlParamArr objectAtIndex:0],[urlParamArr objectAtIndex:1]);

    //BOOL endTrain1 = [[urlParamArr objectAtIndex:1] hasPrefix:@"subCatValue"];
    //BOOL endTrain2 = ([urlParamArr objectAtIndex:1
    //NSLog(@"Number of elements: %@",[urlParamArr count]);
    if (navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        //NSLog(@"Enter into His glory");

        if ([urlString hasSuffix:@"categories_list.php"]) {

            //NSLog(@"2nd Heaven");
            continueOrExit = YES;

        }else if ([[urlParamArr objectAtIndex:1] hasPrefix:@"subCatValue"]) {
            continueOrExit = NO;
            NSLog(@"end of the train");
            NSArray *firstParamStringArr = [[urlParamArr objectAtIndex:0] componentsSeparatedByString:@"="];
            NSArray *secondParamStringArr = [[urlParamArr objectAtIndex:1] componentsSeparatedByString:@"="];
            NSString *catSelected = [firstParamStringArr objectAtIndex:1];
            NSString *subCatSelected = [secondParamStringArr objectAtIndex:1];



            //go back to native app
            [self goBackToMain:catSelected andSubCat:subCatSelected];



        }
    }
    return continueOrExit;
}

Actually in the above function where I am calling the goBackToMain method I want it to call the delegate method and return to the mainviewcontroller. Unfortunately after executing that goBackToMain method it goes back to this method and continue to return continueOrExit.

Is there anyway to make it truly exit without returning anything? I've tried putting in multiple returns to no avail. Or can I in the html page pass some javascript to directly call this method so that I don't have to go through this delegate method?

Thanks for the help in advance!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c