繁体   English   中英

UITableViewCell没有将触摸事件传递给子视图,为什么?

[英]UITableViewCell does not deliver touch event to subview, why?

我已经向单元格添加了一个子视图:

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)

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

UITableViewCell的! {

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

tableView的框架高度设置为0,这就是为什么未传递touch事件的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM