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)!")
}
}
我的問題是,accessoryType和selectionStyle沒有得到改變。 tableView.separatorStyle確實和cell.textlabel.text一樣發生了變化。 我該如何解決這個問題?當被選擇時斯威夫特的tableView細胞集附件類型
注意:'tableView:cellForRowAtIndexPath:'可能不是設置'tableView.separatorStyle'的正確位置。我會將這行代碼移到'viewWillAppear',或者甚至嘗試在界面生成器中進行設置(我沒有訪問最新的Xcode,所以我不能快速嘗試)。 – dasblinkenlight