2013-01-10 36 views
1

可能重複:
How can I disable the UITableView selection highlighting?selectionStyle在iPhone UITableViewCell selectionStyle編輯時?

當您在一個UITableView點按行,該行突出顯示和選擇。是否有可能禁用此功能,因此點擊一行無能爲力?

+0

DUP中​​的文章,我更喜歡低票的答案是設置allowsSelection =在tableView上的屬性NO。 – danh

+0

將'allowSelection'設置爲'NO'是好的,但前提是您希望整個表視圖具有不可選擇的行。爲了更好地控制單個單元格的選擇性,可以使用'UITableViewCell'的'selectionStyle'屬性。 – Pripyat

回答

4

是下面的代碼將禁用用戶交互,如果突出部分要禁用,你需要寫一些,如果一些特定的細胞 - 別的方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    cell.userInteractionEnabled = NO; 

    return cell; 
} 
+0

這將防止細胞接收觸摸事件,這可能不是他想要的。 –

+0

好吧,如果你禁用用戶交互,用戶不能點擊它:),並且他反正使用的可能是假賬戶 –

1

如果你有你的按鈕或任何東西,還需要是「可觸摸」,不僅僅是設置選擇風格無:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

如果它只是一個文本比你可以像空間塵埃細胞建議。

1

已回答這個問題before

抓住UITableViewCell實例,並設置以下屬性:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
1

你也可以試試這個:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    //do ur stuff 

} 
相關問題