Swift:uiimageview 的 UITapGestureRecognizer 在自定义视图中终止应用程序

Swift: UITapGestureRecognizer for uiimageview terminate app in custome view

我从基础 class (MSC_CLItem) 中扩展了一些 Class,如下所示:

class MSC_CLItem
{
    var Type:MSC_CustomListType!

    func RenderUI(Point:CGPoint) -> UIView
    {
        return UIView(frame: CGRect.zero)
    }
}

每个扩展 class 必须覆盖 RenderUI func 才能生成自己。所有扩展对象都将添加到 UIScrollView 中。现在我的问题是: 自定义视图内带有 TapGesture 的 uiimageview 未检测到动作。例如我的 class 是:

class MSC_CLItem_Tizer : MSC_CLItem
{
    var Title:String!
    var Video:MSC_CLItem_TizerVideo!
    var Detail:MSC_CLItem_TizerDetail!

    private init(title:String!)
    {
        super.init()
        self.Title = title
        super.Type = .Tizer
    }

    override func RenderUI(Point:CGPoint) -> UIView
    {
        let v = UIImageView()
        v.backgroundColor = UIColor.yellowColor()
        let screenSize: CGRect = UIScreen.mainScreen().bounds
        v.frame.size = CGSize(width: screenSize.width - 10, height: CGFloat(160))
        v.frame.origin = Point

        let vid = UIImageView()
        vid.image = UIImage(named: "default")
        vid.backgroundColor = UIColor.grayColor()
        vid.contentMode = .ScaleAspectFill
        vid.af_setImageWithURL(NSURL(string: "Image HTTP url")!)
        vid.frame.size = v.frame.size
        vid.frame.origin = CGPoint(x: 0, y: 0)
        vid.clipsToBounds = true
        vid.userInteractionEnabled = true
        v.userInteractionEnabled = true
        let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("imageTapped:"))
        vid.addGestureRecognizer(tapRecognizer)
        v.addSubview(vid)
    }

    func imageTapped(gestureRecognizer: UITapGestureRecognizer) {
        //Not detected to here
    }
}

当我点击图片时出现以下错误:

NSForwarding: 警告: class 'MSC_CLItem_Tizer' 的对象 0x7c8cc830 没有实现 methodSignatureForSelector: -- 前面有问题 无法识别的选择器 -[MSC_CLItem_Tizer imageTapped:]

我很困惑我的代码的哪一部分是错误的?

谢谢

我想这可能是个问题。写这一行不带“:”

let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("imageTapped"))

您必须将超级 class 声明为 NSObject

class MSC_CLItem : NSObject
{
  ......
}


let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("imageTapped:"))
tapGesture.numberOfTouchesRequired = 1;
tapGesture.numberOfTapsRequired = 1;
vid.addGestureRecognizer(tapRecognizer)
v.addSubview(vid)
self.view.addSubview(v)

了解更多详情

没有实现 methodSignatureForSelector: — 麻烦了

Got Unrecognized selector -replacementObjectForKeyedArchiver: crash when implementing NSCoding in Swift [Xcode 6 GM]