2009-11-25 43 views
5

我想禁用點擊特定的Cell.it意味着,當我們觸摸特定的單元格時,我不想顯示突出顯示顏色(選擇指示)?請幫忙嗎?如何隱藏對UITableview的選擇?

+0

對不起。我找到了解決方案.. [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; – 2009-11-25 11:32:08

回答

15

使用cell.selectionStyle = UITableViewCellSelectionStyleNone;或返回false或返回null代表方法tableView:willSelectRowAtIndexPath

+0

我在故事板中將樣式設置爲none,但我的分隔線變得狂暴。顯然這是由於沒有閱讀文檔,在指定的委託方法中返回nil解決了問題......謝謝你爲我節省了一些時間。 – 2014-08-28 16:15:55

0

斯威夫特

如果您使用的是自定義單元格:如果你沒有使用自定義單元格

class YourCustomCell: UITableViewCell { 
    override func awakeFromNib() { 
     setup() 
    } 

    init() { 
     setup() 
    } 

    required init?(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
    } 

    fileprivate func setup() { 
     self.selectionStyle = .none 
    } 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifierID") 
    cell.selectionStyle = .none 
    return cell 
} 

紅利:如果您想隱藏小區選擇並且也不想撥打func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {...},那麼只需設置cell.isUserInteractionEnabled = false。但是,這不是一個好的做法。