2013-03-25 97 views
0

我試圖實現一個'設置頁面'的分隔視圖,左側爲一個表視圖,右側爲一個圖像視圖。一切都很好,但如果嘗試更快地點擊它,則表格視圖單元格觸摸會出現延遲。 DidSelectRowAtIndex路徑沒有被調用,但單元格閃爍。UITableViewCell觸摸響應的延遲

我已經試過,

  1. 移動影像變更邏輯爲willSelectRowAtIndexPathDidSelectRowAtIndex

  2. 去除一切從委託方法(來檢查它是否是由於圖像的加載 )

我該如何解決這條線問題?

TableDatasource

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *cellIdentifier = @"tutorialCell"; 
     CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
     if (cell == nil) { 
      NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TutorialTableCell" owner:nil options:nil]; 
      cell = [nib objectAtIndex:0];   
     } 
     NSDictionary * dic = [dictArray objectAtIndex:indexPath.row]; 
     cell.tutorialText.text = [dic valueForKey:TUTORIAL_TEXT]; 
     cell.tutorialImage.image = [UIImage imageNamed:[dic valueForKey:TUTORIAL_ICON]]; 
     cell.contentView.backgroundColor = [UIColor colorWithHex:@"#36393D" alpha:1.0]; 
     UIView *bgColorView = [[UIView alloc] init]; 
     [bgColorView setBackgroundColor:[UIColor colorWithHex:@"#1f1f1f" alpha:1.0]]; 
     [cell setSelectedBackgroundView:bgColorView]; 
     return cell; 
    } 

的TableView委託

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSDictionary * dic = [dictArray objectAtIndex:indexPath.row]; 
    _tutorialImageView.image = [UIImage imageNamed:[dic valueForKey:TUTORIAL_IMAGE]]; 
} 

回答

2

UITableViews是已經默認啓用delaysContentTouches UIScrollViews的子類。這是因爲UIScrollView在允許觸摸到其子視圖之前嘗試確定觸摸是否是滑動手勢或滾動動作的一部分。如果您確實想禁用該操作,可以將表格視圖的delaysContentTouches設置爲NO。這可能會使滾動行爲有點奇怪,因爲水龍頭立即轉到您的表視圖的單元格。您可能會發現,您確實比延遲觸摸動作更喜歡延遲觸摸動作。

編輯克萊門特說他已經試過了,所以這裏有另一個想法。

在發佈的代碼中,您至少在最初時從磁盤加載這些圖像(imageNamed:)。 UIKit可能會做一些緩存。如果你的教程圖片非常大,你可以做得更快來加載它們,所以應該提前加載它們。您可以加載所有圖像,並使用這些相同的[dic valueForKey:TUTORIAL_IMAGE]鍵將它們放入字典中。然後在tableView:didSelectRowAtIndexPath:中,您可以將_tutorialImageView.image設置爲字典中的一個(已加載)圖像。

+0

它已被設置爲否在界面生成器中,我甚至試圖把它放在'viewdidload'中,但行爲沒有變化。 – 2013-03-25 06:38:57

+0

@Clement好的,編輯中的新建議。另外,你有沒有嘗試用儀器分析這個代碼?如果它確實是一個性能問題,它將有助於瞭解最重的回溯。 – 2013-03-25 06:51:09

+0

謝謝。我嘗試了你的建議 – 2013-03-25 07:14:13

0

這可能是圖像加載代碼。我在這裏有兩個建議:

a。如果圖像不是太多,你可以加載它們並將它們緩存在NSArray中。

b。如果內存是一個問題,我建議首先顯示一個佔位符圖像和/或一個UIActivityIndi​​cator,然後將主圖像加載到離開主線程的單獨線程中。