ios – didSelectRowAtIndexPath未被调用(Swift)

栏目: Swift · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/25904331/didselectrowatindexpath-not-being-called-swift

我已经在圈子里呆了一段时间,我在相关帖子中发现的任何东西似乎都没有解决它.

我是以编程方式将表添加到自定义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)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

小米生态链战地笔记

小米生态链战地笔记

小米生态链谷仓学院 / 中信出版集团 / 2017-5 / 56.00

2013年下半年,小米开始做一件事,就是打造一个生态链布局IoT(物联网);2016年年底,小米生态链上已经拥有了77家企业,生态链企业整体销售额突破100亿元。这3年,是小米生态链快速奔跑的3年,也是小米在商场中不断厮杀着成长的3年。 3年,77家生态链企业,16家年销售额破亿,4家独角兽公司,边实战,边积累经验。 小米生态链是一个基于企业生态的智能硬件孵化器。过去的3年中,在毫无先......一起来看看 《小米生态链战地笔记》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

随机密码生成器
随机密码生成器

多种字符组合密码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具