首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >swift: didSelectRowAtIndexPath

swift: didSelectRowAtIndexPath
EN

Stack Overflow用户
提问于 2017-03-12 23:20:23
回答 2查看 6.3K关注 0票数 1

我有tableViewController。我想单击1个细胞并获取print("0"),然后单击2个细胞并获取print("1")

但是我的代码不能工作。为什么?

代码语言:javascript
复制
import UIKit

class MasterViewController: UITableViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 10 
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: String(format: "Cell%d", indexPath.row), for: indexPath)
    return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    if indexPath.row == 0 {
        print("0")
    }

    else if indexPath.row == 1 {
        print("1")
        self.performSegue(withIdentifier: "detailSegue", sender: self)
    }

}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-03-12 23:40:44

在Swift 3中,UITableViewController中方法的签名是

代码语言:javascript
复制
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
票数 3
EN

Stack Overflow用户

发布于 2017-03-12 23:45:07

看起来你是想把Swift 3和老版本混在一起。请将其更改为:

代码语言:javascript
复制
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42749136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档