【发布时间】:2015-05-25 17:20:47
【问题描述】:
我知道已经有一些关于此的问题,但我找不到解决方案。 有一个非常简单的代码在我的一个项目上运行良好,但在另一个项目上却不行:
这是 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()
}
}
我确定解决方案很简单,但我找不到。
【问题讨论】:
-
“不工作”是什么意思?
-
我的意思是当我触摸视图时,没有 AlertView 出现
-
尝试在函数中使用简单的 println() 来查看是否不是 alertview 的错误?
-
其实我在函数中使用了断点,但应用程序一直没有停止
-
您的视图的超级视图是否启用了
userInteractionEnabled?
标签: ios swift touchesbegan