Im carico di una vista tabella da un file plist. Questo funziona senza problemi. Voglio semplicemente "spuntare" le righe a schede. Al momento con il mio codice non funziona come desiderato. Al momento loos in questo modo:Seleziona più righe in tableview e spunta quelle selezionate
- rubinetto row1 (sarà tick riga 1 = buono)
- rubinetto row1 di nuovo (non succede niente = male mi aspettano qui la fila per essere spuntata.) Mentre toccando nuovamente sulla riga 1 si spegne quindi. dopo che il secont tap su di esso.
- Quando si tocca row0 al caricamento iniziale della Tableview non mi ha mai zecche fila
il mio codice:
class portals: UITableViewController {
var lastSelectedIndexPath = NSIndexPath(forRow: -1, inSection: 0)
...
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
cell.textLabel!.text = portals[indexPath.row]
return cell
}
// Check which portal is selected
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var whichPortalIsSelected: String = ""
// Get Cell Label
let indexPath = tableView.indexPathForSelectedRow();
// Tick the selected row
if indexPath!.row != lastSelectedIndexPath?.row {
let newCell = tableView.cellForRowAtIndexPath(indexPath!)
newCell?.accessoryType = .Checkmark
lastSelectedIndexPath = indexPath
whichPortalIsSelected = newCell!.textLabel!.text!
println("You selected cell #\(lastSelectedIndexPath.row)!") //PPP
println("You selected portal #\(whichPortalIsSelected)!") //PPP
// Un-Tick unselected row
} else {
let newCell = tableView.cellForRowAtIndexPath(indexPath!)
newCell?.accessoryType = .None
whichPortalIsSelected = newCell!.textLabel!.text!
println("You unselected cell #\(indexPath!.row)!") //PPP
println("You unselected portal #\(whichPortalIsSelected)!") //PPP
}
}
}
Questo non sembra funzionare. 'tableView: didSelectRowAtIndexPath:' viene chiamato solo quando la riga è selezionata, non quando è deselezionata, quindi 'cell.selected' sarà sempre vero! – entropid