上記の画像の様にUITableViewにUISwitchを設置しています。
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") as! CustomTableViewCell cell.textLabel!.text = member.memberNames[indexPath.row] return cell } }
class CustomTableViewCell: UITableViewCell { @IBOutlet weak var mySwitch: UISwitch! @IBAction func hundleSwitch(_ sender: Any) { if mySwitch.isOn{ print("on") } else { print("off") } } }
現状上記の様にCustomTableViewCellにUISwitchを接続してSwitchをオン・オフするとprintで文字を出力するようにしております。
何番目のセルのSwitchが変更されたか、インデックス番号を取得する方法を
どなたかご教示いだだけませんでしょうか。
よろしくお願いいたします。
回答2件
良いと思った回答にはグッドを送りましょう。
グッドが多くついた回答ほどページの上位に表示されるので、他の人が素晴らしい回答を見つけやすくなります。
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2017/06/07 04:34