2010-06-18 56 views
1

好的,我真的花了2天时间,这让我难住了。解雇uiwebview

从我的主要的UIViewController我叫WebViewController这是一个UIWebView里面一个UIViewController:

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

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

的UOLCategoriesWebViewController里面我已经打电话委托方法shouldStartLoadWithRequest当用户点击一个特定类型的链接,其中它解析出PARAMS并返回到主的UIViewController(或者至少,这就是我想要它做):

- (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; 
} 

其实在上面的函数在那里我打电话了goBackToMain方法我希望它调用委托方法并返回到mainviewcontroller。不幸的是,在执行goBackToMain方法后,它返回到此方法并继续返回continueOrExit。

无论如何要真正退出而不返回任何东西吗?我试图把多个回报无济于事。或者我可以在HTML页面传递一些JavaScript来直接调用这个方法,这样我就不必经历这个委托方法了?

感谢您的帮助!

+0

我有点麻烦理解你到底在做什么。如果url后缀是你想加载的categories_list.php,如果不是你想做一些东西然后解雇? – Rudiger 2010-06-18 05:50:31

+0

是的,这是完全正确的:) – chimgrrl 2010-06-18 06:11:55

+0

你是什么意思退出没有返回任何东西...我没有得到你的确切目的... – 2010-06-18 06:31:42

回答

1

你可以尝试的是在委托方法执行后推迟goBackToMain:andSubCat:的调用。这样,代理方法可以返回并调用然后处理:

NSArray *firstParamStringArr = [[urlParamArr objectAtIndex:0] componentsSeparatedByString:@"="]; 
NSArray *secondParamStringArr = [[urlParamArr objectAtIndex:1] componentsSeparatedByString:@"="]; 
NSString *catSelected = [firstParamStringArr objectAtIndex:1]; 
NSString *subCatSelected = [secondParamStringArr objectAtIndex:1]; 

NSMethodSignature *sig = [self methodSignatureForSelector:@selector(goBackToMain:andSubCat:)]; 
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig]; 
[inv retainArguments]; 
[inv setTarget:self]; 
[inv setSelector:selector]; 
[inv setArgument:&catSelected atIndex:2]; 
[inv setArgument:&subCatSelected atIndex:3]; 
[inv performSelector:@selector(invoke) withObject:nil afterDelay:0.0]; 
+0

谢谢!这给了我一个良好的开始正确的方向:) – chimgrrl 2010-06-18 09:08:52