iPhoneアプリを作っているのですが、tableViewのCellを押した時に背景色をclearとlightGrayを入れ替えたいのですが、うまく行きません。押した時にlightGrayにはなりますが、再度押してもclearされません。
printすると
タップされたセルのindex番号false: 1
タップされたセルのindex番号true: 1
と交互に処理が実行されているのに、なぜ、
cell.backgroundColor = UIColor.clear
で色が透明に戻らないのかご教授下さい。
(sigDataArrayは配列でcell毎のデータを格納しています。)
swift
1// セルがタップされた時の処理 2func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 3 tableView.deselectRow(at: indexPath, animated: false) 4 let cell = tableView.dequeueReusableCell(withIdentifier: "irSigCell", for: indexPath) 5 // 状態と色を変更する 6 if (sigDataArray[indexPath.row].tapSelect)! { 7 sigDataArray[indexPath.row].tapSelect = false 8 cell.backgroundColor = UIColor.clear 9 print("タップされたセルのindex番号true: (indexPath.row)") 10 } else { 11 sigDataArray[indexPath.row].tapSelect = true 12 cell.backgroundColor = UIColor.lightGray 13 print("タップされたセルのindex番号false: (indexPath.row)") 14 } 15}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/05 02:51