0

以下代码导致我的游戏崩溃..如果我将其注释掉,我根本没有问题..我真的看不出任何错误..我首先认为这可能是由内存问题引起的,但在我的dealloc 方法我正在释放视图和 webview.. 我做错了什么?

view = [[UIView alloc] initWithFrame:CGRectMake(0, self.boundingBox.size.width, self.boundingBox.size.width, self.boundingBox.size.height)];

         NSString *urlAddress=@"http://www.google.com";

         NSURL *url = [NSURL URLWithString:urlAddress];
         NSURLRequest *reqObject=[NSURLRequest requestWithURL:url];
         webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.boundingBox.size.width, self.boundingBox.size.height )];
         webView.delegate = self;
         [webView loadRequest:reqObject];
         [view addSubview:webView];

        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button setImage:[UIImage imageNamed:@"ok-button"] forState:UIControlStateNormal];

        [button addTarget:self
                   action:@selector(web)
         forControlEvents:UIControlEventTouchDown];
        [button setTitle:@"Show View" forState:UIControlStateNormal];
        button.frame = CGRectMake(self.boundingBox.size.width - 40, 10, 30, 30.0);
        [view addSubview:button];

         [[[CCDirector sharedDirector] openGLView] addSubview:view];
4

1 回答 1

0

我在 cocos2d 游戏中使用 UIWebview 并且工作正常。这是我的代码:

        AppController *app =  (AppController*)[[UIApplication sharedApplication] delegate];

        self.infoWebView = [[UIWebView alloc] initWithFrame:webFrame];
        self.infoWebView.backgroundColor = [UIColor whiteColor];

        self.infoWebView.scalesPageToFit = YES;
        self.infoWebView.layer.cornerRadius = 15;
        self.infoWebView.layer.borderWidth = 5;
        self.infoWebView.layer.borderColor = [[UIColor whiteColor] CGColor];

        self.infoWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
        self.infoWebView.delegate = self;
        self.infoWebView.clipsToBounds = YES;

        [app.navController.view addSubview:self.infoWebView];

        [self.infoWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:GOODIES_HTML]]];
于 2013-01-24T08:28:10.363 回答