Nel mio UITableViewController ho un cellulare personalizzato che contiene un whoce switcher è la seguente:Swift/UISwitch: come implementare un delegato/ascoltatore
import Foundation
import UIKit
class SwitchCell: UITableViewCell {
@IBOutlet weak var label : UILabel!
@IBOutlet weak var switchEmail : UISwitch!
func setEditable(canEdit:Bool) {
if (canEdit) {
self.switchEmail.enabled = true
self.label.highlighted = false
}
else {
self.switchEmail.enabled = false
self.label.highlighted = true
}
}
func configureCellWithSwitch(labelText:String, switchValue:Bool, enabled:Bool) {
var labelFrame:CGRect = self.label.frame
labelFrame.size.height = Settings.labelHeight
self.label.frame = labelFrame
self.label.text = labelText
if (switchValue) {
self.switchEmail.setOn(true, animated: true)
}
else {
self.switchEmail.setOn(false, animated: true)
}
self.setEditable(enabled)
}
}
Vorrei sapere come implementare un ascoltatore/delegato allo switcher per ottenere il suo valore da UITableViewController. Sono stato in grado di scrivere delegato/ascoltatori per cella con UITextField e UITextView attuazione dei metodi
func controller(controller: UITableViewCell, textViewDidEndEditing: String, atIndex: Int)
e
func controller(controller: UITableViewCell, textFieldDidEndEditingWithText: String, atIndex: Int)
ma non so che cosa devo implementare per lo switcher.
Ok, questo è ciò che ho appena scritto all'interno della cellula classe nel init(). Mi piacerebbe sapere come posso recuperare il valore dello switch dal mio controller di visualizzazione tabella ... quale metodo dovrei implementare lì? –
@LoryLory vedere il mio aggiornamento: il valore di 'UISwitch' è disponibile tramite' .on' – Daniel
Ah ok, quel metodo dovrebbe essere all'interno del TableView giusto? Ho pensato che fosse all'interno della cella della classe personalizzata ... ecco perché non sapevo come ottenere il valore dal controller della vista tabella –