UITableViewCell不向子视图提供触摸事件,为什么?

时间:2014-08-28 12:18:58

标签: ios uitableview swift

我在单元格中添加了一个子视图:

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)

2 个答案:

答案 0 :(得分:0)

覆盖func tableView(tableView:UITableView!,cellForRowAtIndexPath indexPath:NSIndexPath!) - >

的UITableViewCell! {

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

答案 1 :(得分:0)

tableView的框架高度设置为0,这就是未交付触摸事件的原因。