将URL加载到本地文件的webview中

时间:2012-12-08 23:29:22

标签: javascript xcode webview

我能够将iTunes文件共享中的本地文件(例如“index.htm”)加载到webview中

我的问题在于当我尝试从搜索文本uitextbox打开链接时。在这里,我搜索字符串“mow now”

NSString *currentURL = [viewWeb.request.URL absoluteString];
//cleanup
NSString *match = @"Documents/";
NSString *preTel;
NSString *postTel;

NSScanner *scanner = [NSScanner scannerWithString:currentURL];
[scanner scanUpToString:match intoString:&preTel];
NSString *finalString = [NSString stringWithFormat:@"%@contents/search.htm?search=%@&menu=0&submitType=Search", preTel,fixedSpaces];

文件:///var/mobile/Applications/################/contents/search.htm搜索=现在&安培+刈;菜单= 0&安培; submitType =搜索?

### =我的iphone沙箱代码(我想?)

NSString *fullURL = finalString;
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[viewWeb loadRequest:requestObj];

..并且页面无法加载。 :(

1 个答案:

答案 0 :(得分:0)

FIXED:缺少的是stringWithFormat中的“Documents”(区分大小写)。

NSString *finalString = [NSString stringWithFormat:@"%@Documents/contents
                         /search.htm?search=%@&menu=0&submitType=Search",
                           preTel,fixedSpaces];