我知道已经有一些问题,但我找不到解决方案.有一个非常简单的代码可以在我的一个项目上正常工作,但不能在另一个项目上工作:
这是UIView的子类的代码.
import UIKit
class test : UIView {
init(frame: CGRect, color: UIColor) {
super.init(frame: frame)
self.backgroundColor = color
self.userInteractionEnabled = true
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
var alert = UIAlertView()
alert.title = "lol"
alert.message = "lol"
alert.addButtonWithTitle("Ok")
alert.show()
}
}
Run Code Online (Sandbox Code Playgroud)
我确信解决方案很简单,但我找不到它.