Wiem, że są już pewne pytania na ten temat, ale nie mogłem znaleźć rozwiązania. Istnieje bardzo prosty kod, który działa dobrze na jednym z moich projektów, ale nie na innym:touchesBegan nie jest wywoływana w podklasie UIView
Oto kod podklasy 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()
}
}
Jestem pewien, że rozwiązanie jest dość proste, ale nie mogę go znaleźć.
Co masz na myśli mówiąc "nie działa"? – rdelmar
Mam na myśli to, że po dotknięciu widoku, brak wyświetlenia alertów –
próbował użyć prostego println() w funkcji, aby zobaczyć, czy to nie błąd z alertu? – Wraithseeker