2015-04-23 44 views
0

我接手了一個項目,其中包含custom UITableViewCell。當我選擇單元格上的單元格時,該單元格會突出顯示。 現在我想刪除此行爲,但當我設置[cell setSelectionStyle:UITableViewCellSelectionStyleNone];單元格變爲禁用,我無法再選擇它。有沒有人知道爲什麼會這樣?提前致謝。當我將selectionStyle設置爲UITableViewCellSelectionStyleNone時,自定義UITableViewCell被禁用。

+0

你不應該這樣做: '[tableView setCellSelectionStyle:UITableViewCennSelectionStyleNone]'? –

+0

@Lords Zsolt不要這樣...... – LoVo

+0

你是什麼意思,不能再選擇它了?它是否調用didSelectRow? –

回答

0

謝謝大家的幫助,我剛找到解決方案。前者開發人員實施了一種方法,在每個選定單元格上添加自定義選擇視圖,並使用默認顏色使其看起來像缺省單元格選擇行爲。我已經要求版主刪除該問題。

0

以下代碼完全正常工作。它設置樣式爲none(所以不突出),但仍選擇(主叫didselectrow):

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 5; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 10; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"%s", __PRETTY_FUNCTION__); 
    [tableView deselectRowAtIndexPath:indexPath animated:NO]; 
} 

你在哪裏設置selectionstyle?那個自定義的tableviewcell類會發生什麼事情,可能會破壞代碼?

相關問題