2011-04-18 23 views
5

嘿,我得到一個非常奇怪的錯誤,我無法弄清楚如何解決它:當我在UITableView中滾動時,它有時會突出顯示藍色的單元格,即使當我沒有完全選擇。UITableViewCell在滾動時變成藍色

例如:
- 細胞1-
- 細胞2-
- 細胞3-
- 細胞4-
如果我把手指向下在小區2和滾動到小區4會留下單元格2突出顯示,即使didSelectRowAtIndexPath:從不被觸發。

任何想法?

編輯 添加代碼:

UITableViewCell *cell = nil; 

    static NSString *cellId = @"StyleDefault"; 
    cell = [tableView dequeueReusableCellWithIdentifier:cellId]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] 
       initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId] autorelease]; 
    } 

    cell.textLabel.text = @"Cell One"; 
    cell.textLabel.textAlignment = UITextAlignmentCenter; 
    [cell setAccessoryView:nil]; 

    return cell; 
+0

你能告訴我們cellForRowAtIndexPath中的單元格創建代碼嗎? – 2011-04-18 06:39:03

+0

請告訴我們你在'CellForRowAtIndexPath'委託中做了什麼? – 2011-04-18 06:45:49

回答

0

您可以使用在創建細胞以下。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

cell = Your allocation. 

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

我想你也需要請有看看UIViewTable物業觸摸即延遲內容風格和撤銷內容潤色。

希望這會有所幫助。

+0

當我滾動時,這會擺脫選擇,但不幸的是,如果用戶實際選擇了行,它不會變成藍色。 – Rob 2011-04-18 09:16:16

0

在您的UITableView委託中覆蓋-tableView:willSelectRowAtIndexPath:並返回nil,以確保您不允許它選擇行。

+0

我想他希望細胞可以選擇。他的觀點是當你滾動視圖時。 – 2011-04-18 07:06:04

+0

這不允許我選擇行 – Rob 2011-04-18 09:16:34

1

固定它!

我的解決辦法是兩個部分組成:

1)的cellForRowAtIndexPath:把「cell.selected = NO;」,它修正如果小區被降落在隨後的問題熄滅屏幕(滾動)。

UITableViewCell *cell = nil; 

static NSString *cellId = @"StyleDefault"; 
cell = [tableView dequeueReusableCellWithIdentifier:cellId]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId] autorelease]; 
} 

cell.textLabel.text = @"Cell One"; 
cell.textLabel.textAlignment = UITextAlignmentCenter; 
[cell setAccessoryView:nil]; 

//Here: 
cell.selected = NO; 

return cell; 

2)把「[tableView deselectRowAtIndexPath:indexPath animated:YES];」到didSelectRowAtIndexPath:而不是我曾經有「[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO];」這在很多層面上都是錯誤的。

[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

希望能幫助有這個問題的人。案件結案。

相關問題