Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何运行HTML+;在UIWebView上运行的javascript文件。?_Javascript_Iphone_Html_Ios_Uiwebview - Fatal编程技术网

如何运行HTML+;在UIWebView上运行的javascript文件。?

如何运行HTML+;在UIWebView上运行的javascript文件。?,javascript,iphone,html,ios,uiwebview,Javascript,Iphone,Html,Ios,Uiwebview,各位, 我有一个HTML页面,其中包含一个Javascript函数,显示一个动物动画。。我已经在xcode项目中本地添加了它 现在,当我在UIWebView中加载此文件时,它看起来会很完美。。 下面是将HTMl文件加载到UIWebView的代码 NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"elephant-animation" ofType:@"html"] isDirectory:NO

各位,

我有一个HTML页面,其中包含一个Javascript函数,显示一个动物动画。。我已经在xcode项目中本地添加了它

现在,当我在UIWebView中加载此文件时,它看起来会很完美。。 下面是将HTMl文件加载到UIWebView的代码

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"elephant-animation" ofType:@"html"] isDirectory:NO];
        NSURLRequest *req = [NSURLRequest requestWithURL:url];
        [self performSelectorOnMainThread:@selector(startWebLoad3:) withObject:req waitUntilDone:YES];

-(void)startWebLoad3:(NSURLRequest *)request
{
    [wbView3 loadRequest:request];
    [wbView3 setBackgroundColor:[UIColor clearColor]];
    wbView3.scrollView.scrollEnabled = NO;
    [wbView3.scrollView setBackgroundColor:[UIColor clearColor]];
    [wbView3 setOpaque:NO];
}
但我有6页。当开始使用单独的UIWebView加载每个页面时,它会转到内存警告。。给我一个这样的错误

void SendDelegateMessage(NSInvocation*): delegate (webView:didFinishLoadForFrame:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
若我只运行一个页面,那个么它会运行得很好,但当我开始一起加载或者一个接一个地加载时,它会崩溃,并伴有内存警告

如果有人能找到解决办法,请告诉我

我一直在解决这个问题

谢谢,

静态NSInteger currentIndex=0;
static NSInteger currentIndex = 0;
if (currentIndex < 99) {
    currentIndex++;
}
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"file%d",currentIndex] ofType:@"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData: 
                        [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
[self.myWebView loadHTMLString:htmlString baseURL:nil];
如果(当前索引<99){ currentIndex++; } NSString*路径=[[NSBundle mainBundle]路径用于资源:[NSString stringWithFormat:@“文件%d”,currentIndex]类型:@“html”]; NSFileHandle*readHandle=[NSFileHandle fileHandleForReadingAtPath:path]; NSString*htmlString=[[NSString alloc]initWithData: [readHandle readDataToEndOfFile]编码:NSUTF8StringEncoding]; [self.myWebView加载htmlString:htmlString baseURL:nil];

我希望它能工作

我想,你想在webview中创建html文件,在我的应用程序中,我在该视图中创建了一个scrollview,在该视图中,我在循环中添加webview,最后在webview中添加html文件。 请尝试以下代码:

ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,768,[[UIScreen mainScreen] bounds].size.height)];
    ScrollView.contentSize = CGSizeMake(768*21,[[UIScreen mainScreen] bounds].size.width);
    ScrollView.pagingEnabled=YES;
    ScrollView.delegate = self;
    ScrollView.userInteractionEnabled = YES;
    ScrollView.showsVerticalScrollIndicator=NO;
    ScrollView.showsHorizontalScrollIndicator=NO;

    int x=0,y=125;
    for ( i=1; i<22; i++)
    {

        view3=[[UIView alloc]initWithFrame:CGRectMake(x,0,768, 1000)];
        view3.backgroundColor=[UIColor whiteColor];

        webview2=[[UIWebView alloc]initWithFrame:CGRectMake(0,y,768,755)];
        webview2.scalesPageToFit=YES;
        webview2.autoresizingMask=(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
        webview2.multipleTouchEnabled=YES;
        webview2.backgroundColor=[UIColor whiteColor];

        NSString *st = [NSString stringWithFormat:@"1%d",i];
        NSString *str12=[NSString stringWithFormat:@"information_"];
        str12=[str12 stringByAppendingString:st];
        NSString *urlAddress        = [[NSBundle mainBundle] pathForResource:str12 ofType:@"html"];//you can also use PDF files
        NSURL *url                  = [NSURL fileURLWithPath:urlAddress];
        NSURLRequest *requestObj    = [NSURLRequest requestWithURL:url];
        [webview2 loadRequest:requestObj];

        webview2.tag= i + 10;
        [view3 addSubview:webview2];


        [ScrollView addSubview:view3];

        x=x+768;


}
    [self.view addSubview:ScrollView];



}
ScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0768,[[UIScreen mainScreen]bounds].size.height)];
ScrollView.contentSize=CGSizeMake(768*21,[[UIScreen mainScreen]边界].size.width);
ScrollView.PaginEnabled=是;
ScrollView.delegate=self;
ScrollView.userInteractionEnabled=是;
ScrollView.showsVerticalScrollIndicator=否;
ScrollView.showsHorizontalScrollIndicator=否;
int x=0,y=125;

对于(i=1;i最终我得到了解决方案..经过长期的研发,得到了一些有效的解决方案

"JavaScript execution time is limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, the web view stops executing the script"
这就是我无法在UIWebView中加载html页面的原因。。 iPad在应用程序发布时只能处理高达3MB的数据加载。我用的不止这些

所以,我根据需要更改javascript,现在工作了


感谢您的参与。

在下图中,一个用于添加HTML、Javascript和CSS类文件,另一个用于一般XCode文件

用于HTML、Javascript和CSS文件

将文件添加到XCode时:


这对我来说很有用!希望它对所有人都有用。谢谢!!

我已经在很多论坛上搜索并用谷歌搜索了它,但没有得到任何运气…请帮助我…我认为为6个UIWebView加载6个页面是没有必要的,有没有其他方法可以做到这一点?也尝试过…但没有成功…嘿@Jagdish你能分享一下你成功的原因吗?我是uck这里我终于看到了你的成功。@Raju Change Java script..to make exability in iOS-Objective C..“JavaScript执行时间限制为每个顶级入口点10秒。如果你的脚本执行时间超过10秒,web视图将停止执行脚本”你读过我的问题了吗?老兄,我知道如何在UIWebView中播放多个文件,我回答了这个问题。我以为你的问题是加载6个html文件,所以我给出了这个例子。很抱歉错过了交流,在这里使用UIScrollView的原因是什么?在mai视图中滑动不同的html页面,所以我在mainview中添加了scrollview。