7

みなさん、

私は 1 つの動物のアニメーションを表示する 1 つの Javascript 関数を含む 1 つの HTML ページを持っています..私はそれを 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

1ページだけ実行すると完全に実行されますが、すべてをまとめて、または1つずつロードし始めると、メモリ警告でクラッシュしました。

誰かがそれの解決策を見つけたら教えてください..

私はこの問題に固執しています..

ありがとう、

4

4 に答える 4

2

最後に解決策を見つけました..長い研究開発の後、いくつかの効果的な解決策を得ました...

"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 は、アプリの起動時にのみ最大 3 MB のデータ読み込みを処理します。そして、それ以上のものを使用しました。

だから、私は必要に応じてjavascriptを変更し、今は働いています..

参加してくれてありがとう..

于 2012-05-11T11:51:14.817 に答える
1
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];

うまくいくことを願っています

于 2012-05-11T07:37:18.007 に答える
1

下の図では、1 つは HTML、Javascript、および CSS のようなファイルを追加するためのもので、2 つ目は一般的な XCode ファイル用のものです。

HTML、Javascript、および CSS ファイル用

ファイルを XCode に追加するとき:

ここに画像の説明を入力

これは私のために働く..!それがすべての人にとってうまくいくことを願っています。ありがとうございました!!

于 2013-12-17T07:28:49.780 に答える
0

私は、webview で html ファイルを実行したいと思います。私のアプリケーションでは、そのビューで 1 つのスクロールビューを実行しました。そのビューで、最後に webview をループに追加します。このコードを試してください:

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];



}

私のアプリケーションでは、22 の html ページ (information_%i、resource に必要) が webview に追加され、非常にうまく機能しています。

あなたにも役立つことを願っています。

于 2012-05-11T11:21:08.397 に答える