为什么我的UIWebView忽略了我的点击?

时间:2010-08-02 18:48:19

标签: iphone

我有一个简单的iPhone应用程序,它会显示我放在Documents目录中的html内容,但是一旦显示,链接就不起作用了。

从我的app delegate的init方法调用以下代码。

有人可以建议我错过了吗?

-(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];
     webView.delegate=self;
     [webView loadRequest:requestObj];
     window = [[UIWindow alloc] init];
     [window addSubview:webView];
     [window makeKeyAndVisible];
     window.hidden=NO;
} 

2 个答案:

答案 0 :(得分:0)

我认为你不应该创建自己的UIWindow对象。这个对象已经存在于你的xib中,它可能已经在applicationDidFinishLoading方法中使用了“madeKeyAndVisible”。

尝试删除与窗口相关的所有行,并将子视图添加到self.view,如

[self.view addSubview:webView];

答案 1 :(得分:0)

答案结果是有两个裁剪功能:一个用于显示,一个用于交互。

我已将界限设置为屏幕尺寸,但不是我的框架。

很明显吗?不是真的。

相关问题