2013-02-28 37 views
1

我有一個UIWebView作爲UITableView中的單元格。我知道這不是建議的,但WebView不滾動,所以建議無關緊要。我使用Web視圖來設置單元格的樣式和主題。iOS UIWebView setUserInteractionEnabled爲NO不適用於iOS 6

我遇到的問題是,在iOS 6中,當我將userInteractionEnabled設置爲NO時,UIWebView不會將響應事件鏈上的觸摸事件傳遞給它。表視圖從不調用didSelectRowAtIndexPath。我應該注意這在iOS 5中可以正常工作。

我的問題是,Apple是否改變了UIWebView如何處理userInteractionEnabled?

任何評論都會有所幫助。

這是我撥打電話的地方。它被稱爲在正確的單元格實例(我只有在表1週中的WebView細胞)

webView.userInteractionEnabled = NO; 
+0

您是否將webView添加到單元格或cell.contentView? – pbibergal 2013-02-28 16:08:43

+0

我正在使用自定義類。 @interface WebViewTableCell:UIWebView atreat 2013-02-28 16:09:28

+0

當您使用tableView數據源方法構建單元格時,您將它作爲子視圖添加到哪裏? – pbibergal 2013-02-28 16:11:12

回答

2

工作正常的iOS 6

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height)]; 
    NSString *html = @"<div></div>"; 
    [wv loadHTMLString:html baseURL:nil]; 
    wv.userInteractionEnabled = NO; 
    [[cell contentView] addSubview:wv]; 

    return cell; 
} 
+0

它看起來像唯一的區別是,你將它添加到contentview。我想知道是否因爲我的手機沒有超級視圖,觸摸事件會被拋出。我會看看如果實現類似這樣的解決我的問題。謝謝。 – atreat 2013-02-28 16:18:05

+0

如果你想使用單元格的自定義大小,你需要在** tableView willDisplayCell **方法中調整webview的大小。 – pbibergal 2013-02-28 16:20:39

0

我的問題無關,與userInteractionEnabled。

那是因爲我也覆蓋shouldHighlightRowAtIndexPath:方法

- (BOOL) tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.section == 0) { 
     return NO; 
    } 
    return YES; 
} 

,似乎在iOS 6中該禁用觸摸事件在那個indexPath細胞。很高興知道。

相關問題