迅速:didSelectRowAtIndexPath

编程入门 行业动态 更新时间:2024-10-13 20:15:37
本文介绍了迅速:didSelectRowAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有tableViewController.我想单击1个单元格并获取print("0"),然后单击2个单元格并获取print("1")

I have tableViewController. I want to click on 1 cell and get print("0") and click on 2 cell and get print("1")

但是我的代码不起作用.为什么?

But my code doesn’t work. Why?

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) } }

推荐答案

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

In Swift 3 the signature of the method in an UITableViewController is

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

更多推荐

迅速:didSelectRowAtIndexPath

本文发布于:2023-11-26 20:37:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635109.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:didSelectRowAtIndexPath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!