let indexPath = NSIndexPath(forRow: 0, inSection: 0);
self.tableView.selectRowAtIndexPath(indexPath, animated: false,
scrollPosition: UITableViewScrollPosition.None)
self.tableView(self.tableView, didSelectRowAtIndexPath: indexPath)
func tableView(tableView: UITableView!, didSelectRowAtIndexPath
indexPath: NSIndexPath!) {
NSLog("You selected cell number: \(indexPath.row)!")
self.performSegueWithIdentifier("yourIdentifier", sender: self)
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath
indexPath: NSIndexPath) {
let indexPath = tableView.indexPathForSelectedRow()
let currentCell = tableView.cellForRowAtIndexPath(indexPath)
as UITableViewCell
println(currentCell.textLabel!.text)
override func viewDidLoad() {
super.viewDidLoad()
// …
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier:
"categoryCell")
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:
NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("categoryCell",
forIndexPath: indexPath) as UITableViewCell
cell.accessoryType = (lastSelectedIndexPath?.row == indexPath.row)
? .Checkmark : .None
cell.textLabel?.text = categories[indexPath.row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath:
NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
if indexPath.row != lastSelectedIndexPath?.row {
if let lastSelectedIndexPath = lastSelectedIndexPath {
let oldCell = tableView.cellForRowAtIndexPath(lastSelectedIndexPath)
oldCell?.accessoryType = .None
}
let newCell = tableView.cellForRowAtIndexPath(indexPath)
newCell?.accessoryType = .Checkmark
lastSelectedIndexPath = indexPath
}
}