class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet
var tableView: UITableView
var items: String[] = ["We", "Heart", "Swift"]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "myCell")
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return self.items.count;
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("myCell") as UITableViewCell
cell.textLabel.text = self.items[indexPath.row]
cell.accessoryType = UITableViewCellAccessoryType.DetailDisclosureButton
cell.selectionStyle = UITableViewCellSelectionStyle.Blue
tableView.separatorStyle = UITableViewCellSeparatorStyle.None
return cell
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("You selected cell #\(indexPath.row)!")
}
}
mio problema è che l'accessoryType e il selectionStyle non vengono modificate. La tabellaView.separatorStyle viene modificata così come cell.textlabel.text. Come posso risolvere il problema?cellule Swift tableView impostare il tipo di accessorio
Nota: 'tableView: cellForRowAtIndexPath:' probabilmente non è il posto giusto per l'impostazione di 'tableView.separatorStyle'. Sposterei quella riga di codice a 'viewWillAppear', o proverei anche ad impostarla nel builder dell'interfaccia (non ho accesso all'ultimo Xcode, quindi non posso provarlo velocemente). – dasblinkenlight