好的,我真的花了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來直接調用這個方法,這樣我就不必經歷這個委託方法了?
感謝您的幫助!
我有點麻煩理解你到底在做什麼。如果url後綴是你想加載的categories_list.php,如果不是你想做一些東西然後解僱? – Rudiger 2010-06-18 05:50:31
是的,這是完全正確的:) – chimgrrl 2010-06-18 06:11:55
你是什麼意思退出沒有返回任何東西...我沒有得到你的確切目的... – 2010-06-18 06:31:42