2015-11-17 77 views
-1

基本上,我的表正在正確顯示,因爲我希望它是。但是,當我點擊我的單元格時,它不會進入我的didSelectRowAtIndexPath方法。不會調用didSelectRowAtIndexPath

下面的截圖也不顯示任何預裝的didSelectRowAtIndexPath方法。

enter image description here

我的代碼如下:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{ 
    return personList.count 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    let myCell = stockTableView.dequeueReusableCellWithIdentifier("personCell", forIndexPath: indexPath) as UITableViewCell 

    myCell.textLabel?.text = personList[indexPath.row].personName 
    myCell.detailTextLabel?.text = personList[indexPath.row].GetPersonDescription() 

    return myCell 
} 

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){ 
    let myCell = stockTableView.dequeueReusableCellWithIdentifier("personCell", forIndexPath: indexPath) as UITableViewCell 

    let selectedCell = myCell.textLabel?.text 
} 

編輯:經過研究,我意識到,我沒有把我的UITableViewDelegate協議。我試圖在網上找到,但找不到任何解決方案。有人可以幫助我嗎?

+0

您是否設置了tableView.delegate = self,並讓您的類採用UITableViewDelegate協議? –

+0

@QuangHà不,我沒有這樣做。如何設置tableView.delegate = self?在viewDidload? –

回答

0
// Set the UITableViewDataSource and UITableViewDelegate for your class 
    class YourClass: UIViewController, UITableViewDataSource, UITableViewDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
       self.YourTableName.registerClass(UITableViewCell.self, forCellReuseIdentifier: "TotalsCell") 
       // Delegate and DataSource for your TableView 
       YourTableName.dataSource = self 
       YourTableName.delegate = self 
     } 

    } 
+0

謝謝!它解決了我的問題。對不起,我是新來的迅速。 –

+0

不客氣。 – Karlos

相關問題