ios – didSelectRowAtIndexPath未被调用(Swift)
文章来源: https://codeday.me/bug/20190112/510762.html, 本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
我已经在圈子里呆了一段时间,我在相关帖子中发现的任何东西似乎都没有解决它.
我是以编程方式将表添加到自定义UIView.表和行文本显示正确,但是当我在模拟器上运行并尝试单击任何行时,didSelectRowAtIndexPath和willdSelectRowAtIndexPath都不会触发.
我的代码的相关位如下:
import UIKit import AVFoundation @IBDesignable class PerformanceQuestionView: UIView, UITableViewDelegate, UITableViewDataSource { var optionsTable = UITableView(frame: CGRectMake(10,200,250,200)) var optionItems = ["One", "Two", "Three", "Four"] convenience init(rect: CGRect, performanceQuestion:PerformanceQuestion?) { self.init(frame: rect) NSLog("PerformanceQuestionView.init()") self.optionsTable.dataSource = self self.optionsTable.delegate = self self.optionsTable.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell") self.optionsTable.allowsSelection = true } func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { NSLog("numberOfRowsInSection") return optionItems.count } func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { NSLog("cellForRowAtIndexPath") var cell:UITableViewCell = self.optionsTable.dequeueReusableCellWithIdentifier("cell") as UITableViewCell cell.textLabel.text = self.optionItems[indexPath.row] return cell } func tableView(tableView: UITableView!, willSelectRowAtIndexPath indexPath: NSIndexPath!) -> NSIndexPath! { NSLog("You will select cell #\(indexPath.row)!") return indexPath } func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) { NSLog("You selected cell #\(indexPath.row)!") } override func layoutSubviews() { super.layoutSubviews() self.addSubview(optionsTable) } }
删除TapGestureRecognizer对我有用!!!
// var backgoroundTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "DismissKeyboard") // self.view.addGestureRecognizer(backgoroundTap)
翻译自:https://stackoverflow.com/questions/25904331/didselectrowatindexpath-not-being-called-swift
以上所述就是小编给大家介绍的《ios – didSelectRowAtIndexPath未被调用(Swift)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
为你推荐:码农书籍
科学的极致:漫谈人工智能
集智俱乐部 / 人民邮电出版社 / 2015-7 / 49.00元
集智俱乐部是一个从事学术研究、享受科学乐趣的探索者组成的团体,倡导以平等开放的态度、科学实证的精神进行跨学科的研究与交流,力图搭建一个中国的“没有围墙的研究所”。这些令人崇敬的、充满激情与梦想的集智俱乐部成员将带你了解图灵机模型、冯•诺依曼计算机体系结构、怪圈与哥德尔定理、通用人工智能、深度学习、人类计算与自然语言处理,与你一起展开一场令人热血沸腾的科学之旅。