Sto cercando di modificare l'aspetto di un TableViewCell personalizzato con Swift.UI personalizzata TableViewCell selected backgroundcolor swift
Devo farlo tramite il progettista o programmaticamente?
ho provato la seguente:
E qui è il mio codice:
@IBOutlet var tableView: UITableView!
var tableData: [String] = ["One", "Two", "Three", "Four"]
override func viewDidLoad() {
super.viewDidLoad()
// Register custom cell
var nib = UINib(nibName: "vwTblCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "cell")
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.tableData.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as TblCell
cell.lblCarName.text = tableData[indexPath.row]
cell.imgCarName.image = UIImage(named: tableData[indexPath.row])
return cell
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("Row \(indexPath.row) selected")
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 70
}
Grazie :) questo è nella giusta direzione. Ho un problema però: quando clicco su una cella diventa il suo colore di selezione grigio originale, quando clicco sulla cella successiva la cella selezionata in precedenza diventa rossa. Ma la cella attualmente selezionata è sempre grigia. –
Hai provato la prima idea? – Christian
Ho provato entrambi, il comportamento era lo stesso per entrambi i metodi. –