我有一個簡單的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;
}
是否啓用了'userInteraction'? – iwasrobbed 2010-08-02 18:55:39
UIWindow不是在默認的「MainWindow.xib」中創建的? – epatel 2010-08-02 18:56:35
以下行在我的webViewDidFinishLoad委託方法中: \t webView.userInteractionEnabled = true; \t [webView becomeFirstResponder]; – Justin 2010-08-03 09:51:51