2014-08-28 107 views
1

我添加了一個子視圖細胞:UITableViewCell不會將觸摸事件傳遞給子視圖,爲什麼?

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { 

    let l = MEL() 
    l.userInteractionEnabled = true 
    cell.contentView.addSubview(l) 
    return cell 
} 

,但是當我接觸標籤,touchesEnded不會被調用,爲什麼呢?

class MEL: UILabel { 

override func touchesEnded(touches: NSSet!, withEvent event: UIEvent!) { 

     super.touchesEnded(touches, withEvent: event) 
+0

在MEL中覆蓋'func touchesCancelled(_ touches:NSSet!, withEvent event:UIEvent!)'並檢查觸摸是否被取消 – Akhilrajtr 2014-08-28 12:23:27

+0

'touchesCancelled'沒有被調用 – 2014-08-28 12:26:06

回答

0

的tableView的框架高度設定爲0,這就是爲什麼未送達觸摸事件。

0

覆蓋FUNC的tableView - >

的UITableViewCell(的tableView:UITableView的!,的cellForRowAtIndexPath indexPath NSIndexPath!)! {

let l = MEL() 
l.userInteractionEnabled = true 
cell.contentView.addSubview(l) 
return cell 
相關問題