ios – didSelectRowAtIndexPath未被调用(Swift)

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

内容简介:翻译自: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)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

算法心得:高效算法的奥秘(原书第2版)

算法心得:高效算法的奥秘(原书第2版)

(美)Henry S. Warren, Jr. / 爱飞翔 / 机械工业出版社 / 2014-3 / 89.00

【编辑推荐】 由在IBM工作50余年的资深计算机专家撰写,Amazon全五星评价,算法领域最有影响力的著作之一 Google公司首席架构师、Jolt大奖得主Hoshua Bloch和Emacs合作创始人、C语言畅销书作者Guy Steele倾情推荐 算法的艺术和数学的智慧在本书中得到了完美体现,书中总结了大量高效、优雅和奇妙的算法,并从数学角度剖析了其背后的原理 【读者评价......一起来看看 《算法心得:高效算法的奥秘(原书第2版)》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具