[swift4] 特定のTableViewのCellだけ選択不可にしたい

特定のTableViewのCellだけ選択不可にしたい時は、セルにUITableViewCellSelectionStyle.noneを指定する

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

 let cell : UITableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath:indexPath)
 if indexPath.row == 1 {
 // セルの選択不可にする
 cell.selectionStyle = UITableViewCellSelectionStyle.none
 } else {
 // セルの選択を許可
 cell.selectionStyle = UITableViewCellSelectionStyle.blue
 }

 return cell
}

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です