swift3.x
[swift3.0]UITableViewの特定(指定)のcell(セル)を選択させないようにする方法
[環境]
Xcode:8.0
Swift:3.0
iOS:10.0
tableViewの指定した特定のセルを選択(ハイライト)させない方法のご紹介です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
class TestViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { // ストーリーボードでtableViewを設定している場合はoutlet接続してください。 @IBOutlet weak var testTableView: UITableView! // セルに表示する値 var testList = ["Test01", "Test02", "Test03", "Test04", "Test05"] 〜省略〜 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // セルを取得 let cell = tableView.dequeueReusableCell(withIdentifier: "ご自身で定義したIdentifierを入れてね", for: indexPath as IndexPath) // セルに表示する値を設定(一応書いときますね) cell.textLabel!.font = UIFont.systemFont(ofSize: 18) cell.textLabel!.text = self.testList[indexPath.row] // "Test05"のセルを選択(ハイライト)不可にする場合 if (self.testList[indexPath.row] == "Test05") { cell.selectionStyle = UITableViewCellSelectionStyle.none } return cell } 〜省略〜 |
こんな感じで指定した特定のセルを選択(ハイライト)不可にできます。