Swift尝试将表视图单元格上的点击事件链接到控制器方法

Web*_*ube 16 xcode ios swift

我是新手,并且在目标C中没有编程.所以我是新手:-)试图做一些相当简单的事情.链接表视图单元格单击以调用控制器中的方法,如 http://prntscr.com/4m9kf7

编辑:

我在MasterController中有这些方法

  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
  override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
 override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
Run Code Online (Sandbox Code Playgroud)

我在其中4个中添加了断点.当点击单元格时,它不会停在其中任何一个单元格中.见屏幕截图:

http://prntscr.com/4m9ql0

Woo*_*ock 41

您需要实现didSelectRowAtIndexPath委托方法并将处理代码放在其中.

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
     //CODE TO BE RUN ON CELL TOUCH
}
Run Code Online (Sandbox Code Playgroud)