开发者

Why does my UIWebView ignore my clicks?

I have a simple iPhone app which will display html content I have placed in the Documents directory, but once it is displayed, the links do not work.

The following code is called from the init method of my app delegate.

Can anyone suggest what I have missed please?

-(void) loadWebView:(NSString*) appDirectory {
     CGRect rect = CGRectMake(0, 0, 320, 480);
     webView = [[UIWebView alloc] initWithFrame:rect];//init and create the UIWebView
     [webView setBounds:rect];


     // NSString* webViewFile = [appDirectory stringByAppendingString:@"index.html"];
     // NSString* protocol=@"file://";
     // NSString* fullUrl=[protocol stringByAppendingString:webViewFile];
     fullUrl=@"http://www.google.com";
     NSLog(@"Attempting to open url (unencoded) %@", fullUrl);
     fullUrl = [fullUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
     NSLog(@"Attempting to open url (encoded) %@", fullUrl);

     //Create a URL object.
     NSURL *url = [NSURL URLWithString:fullUrl];

     //URL Requst Object
     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]开发者_JAVA技巧;
     webView.delegate=self;
     [webView loadRequest:requestObj];
     window = [[UIWindow alloc] init];
     [window addSubview:webView];
     [window makeKeyAndVisible];
     window.hidden=NO;
} 


I don't think you should create your own UIWindow object. This object is already in your xib and it is probably "madeKeyAndVisible" already in the applicationDidFinishLoading method.

Try to remove all lines relating to window, and add the subview to self.view, like

[self.view addSubview:webView];


The answer turns out to be that there are two clipping functions: one for display and one for interaction.

I had set my bounds to the screen size, but not my frame.

Obvious? Not really.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜