2010-08-02 82 views
0

我有一個簡單的iPhone應用程序,它將顯示我已放置在Documents目錄中的html內容,但一旦顯示,鏈接將不起作用。爲什麼我的UIWebView會忽略我的點擊?

以下代碼是從我的應用程序委託的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* [email protected]"file://"; 
    // NSString* fullUrl=[protocol stringByAppendingString:webViewFile]; 
    [email protected]"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; 
} 
+0

是否啓用了'userInteraction'? – iwasrobbed 2010-08-02 18:55:39

+0

UIWindow不是在默認的「MainWindow.xib」中創建的? – epatel 2010-08-02 18:56:35

+0

以下行在我的webViewDidFinishLoad委託方法中: \t webView.userInteractionEnabled = true; \t [webView becomeFirstResponder]; – Justin 2010-08-03 09:51:51

回答

0

我不認爲你應該創建自己的UIWindow對象。這個對象已經在你的xib中,並且可能已經在applicationDidFinishLoading方法中使用「madeKeyAndVisible」了。

試圖刪除有關窗口中的所有行,子視圖添加到self.view,像

[self.view addSubview:webView]; 
+0

謝謝,我會試一試,然後回報。 雖然沒有nib/xib文件。所有可顯示的內容都是動態的,所以我刪除了它,並打算動態設置所有內容。 – Justin 2010-08-03 09:50:36

+0

然後好運。我認爲,如果不知道如何將事情搞糟,那麼在剝離裸露骨頭時,你會遇到很多麻煩。 – mvds 2010-08-03 10:55:42

0

答案原來是有兩個剪輯功能:一個用於顯示和一個互動。

我已將界限設置爲屏幕大小,但不是我的框架。

明顯嗎?不是真的。