2016-01-07 32 views
-1

該單元格非常簡單,只是一個textLabel。我想點擊單元格然後打印一些單詞。這是一個測試 。但didSelectRowAtIndexPath不起作用。請告訴我爲什麼,謝謝!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") 
    } 

} 
+0

看起來重複。請參閱此答案:http://stackoverflow.com/a/12855662/3051458 –

+0

class ListTableViewController:UITableViewController,UITableViewDelegate {...}它將顯示錯誤:「ListTableViewController」到協議「UITableViewDelegate」的冗餘一致性。 – carly

回答

1

請檢查是否self.tableView.allowsSelection = NO不寫在任何地方。在故事板中,檢查single selection是否在選擇選項卡下被選中。

+0

self.tableView.allowsSelection = NO檢查;我不使用故事板,所以... – carly

+0

檢查XIB文件呢? – Nil

+0

在所有文件中沒有「self.tableView.allowsSelection = NO」 – carly

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) 

    } 

你可以試試這個。

相關問題