didSelectRowAtIndexPath不起作用

时间:2016-01-07 06:34:26

标签: swift uitableview didselectrowatindexpath

单元格非常简单,只是一个textLabel。我想点击单元格,然后打印一些单词。这是一个测试 。但是didSelectRowAtIndexPath不起作用。请告诉我原因,谢谢!

import UIKit
import SnapKit

class ListTableViewController : UITableViewController{
    var itemData: ListTableModel!
    var header: UIView!
    override init(style: UITableViewStyle){
        super.init(style: style)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        itemData = ListTableModel()
        self.tableView.dataSource = self
        self.tableView.delegate = self


    }


    ....


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("mCell", forIndexPath: indexPath)
        cell.textLabel?.userInteractionEnabled = false
        let listCell = cell as! ListTableViewCell
        if let item = itemData.getItemData(indexPath.row) {
            listCell.textLabel!.text = item.valueForKey("title") as? String
        }

        return cell
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        print("indexPathS")
    }

}

2 个答案:

答案 0 :(得分:2)

请检查single selection是否未写入任何地方。在故事板中,检查选择标签下是否选中{{1}}。

答案 1 :(得分:0)

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        let text:NSString = myArray .objectAtIndex(indexPath.row) as! NSString
        delegate?.myMethod(text as String)
        self.navigationController?.popToRootViewControllerAnimated(true)

    }

你可以试试这个。

相关问题