好的,我真的花了两天时间,这让我很难过。
在我的主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 :(得分: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];