UIwebviewでローカルhtmlへのアクセスで困っています。

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
やすし

UIwebviewでローカルhtmlへのアクセスで困っています。

#1

投稿記事 by やすし » 11年前

はじめまして、最近、i-phoneアプリの制作を始めたのですが、
ある動作について困っています。

UIwebviewでローカルhtmlを呼び出したのだし、
そのローカルhtml内でゲームを動かすというような内容になっているのですが、

そのhtml内で読み込んでいるjavascriptが動かず、困っています。

UIwebviewはstoryboardで配置して、
ViewController.h
ViewController.m
で呼び出しています。

javascriptでは、addEventlistenerが動かず、困っております。
どうかご教授ください。

以下、サンプルソースになります。

■viewController.h

コード:

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
[tab=30]@property (weak, nonatomic) IBOutlet UIWebView *gameView;
@end

■viewController.m

コード:

@interface ViewController ()

@end

@implementation ViewController;

- (void)viewDidLoad
{
//    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

        CGRect frame = [[UIScreen mainScreen] applicationFrame];
        CGRect rect = CGRectMake(0,0,frame.size.width, frame.size.height);
        UIWebView *wv = [[UIWebView alloc] initWithFrame:rect];
        wv.scalesPageToFit = YES;
        [self.view addSubview:wv];
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"game" ofType:@"html"];
        [wv loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];


        [super viewDidLoad];

}
■htmlで読み込んでいるjs
document.addEventListener("touchstart",function(){
[tab=30]alert('aaa');
});

このような感じです、何かおかしな点があれば、ご指摘ください。

どうぞよろしくお願いします。

“C言語何でも質問掲示板” へ戻る