私はこれを解決しようとしているすべてのスタックオーバーフローを行ってきましたが、ソリューションのどれも動作しません。未確認セレクタがクラスに送信されるのはなぜですか?
NSInvalidArgumentException」、理由: '+ [HonorsApp.ToastView hideSelf:]:認識されていないセレクタは、クラス0x10b564530' ***まずスローコールに送ら
class ToastView: UIView { static func showInParent(parentView: UIView!, withText text: String, forDuration duration: double_t) { //Count toast views are already showing on parent. Made to show several toasts one above another var toastsAlreadyInParent = 0; for view in parentView.subviews { if (view.isKindOfClass(ToastView)) { toastsAlreadyInParent++ } } var parentFrame = parentView.frame; var yOrigin = parentFrame.size.height - getDouble(toastsAlreadyInParent) var selfFrame = CGRectMake(parentFrame.origin.x + 20.0, yOrigin, parentFrame.size.width - 40.0, toastHeight); var toast = ToastView(frame: selfFrame) toast.textLabel.backgroundColor = UIColor.clearColor() toast.textLabel.textAlignment = NSTextAlignment.Center toast.textLabel.textColor = UIColor.whiteColor() toast.textLabel.numberOfLines = 2 toast.textLabel.font = UIFont.systemFontOfSize(13.0) toast.addSubview(toast.textLabel) toast.backgroundColor = UIColor.darkGrayColor() toast.alpha = 0.0; toast.layer.cornerRadius = 4.0; toast.textLabel.text = text; parentView.addSubview(toast) UIView.animateWithDuration(0.4, animations: { toast.alpha = 0.9 toast.textLabel.alpha = 0.9 }) var timer = NSTimer.scheduledTimerWithTimeInterval(duration, target: self , selector: "hideSelf:", userInfo: nil, repeats: false) //toast.performSelector(Selector("hideSelf"), withObject: nil, afterDelay: duration) } static private func getDouble(toastsAlreadyInParent : Int) -> CGFloat { return (70.0 + toastHeight * CGFloat(toastsAlreadyInParent) + toastGap * CGFloat(toastsAlreadyInParent)); } func hideSelf(timer: NSTimer) { UIView.animateWithDuration(0.4, animations: { self.alpha = 0.0 self.textLabel.alpha = 0.0 }, completion: { t in self.removeFromSuperview() }) } }
この
は私が取得エラーですスタック:
私は、セレクタからクラスに呼び出されるメソッドに@objcを追加しようとしたが、それは無駄になってい
また:hideSelf()
hideSelf(timer: NSTimer)
があれば、クラスはUIViewの継承することによって達成されるNSObjectのから継承することも確認されたような方法を宣言
Selector("hideSelf:")
の方法を宣言
Selector("hideSelf")
私は間違っていません。
私はアンドロイドでトースト機能などの迅速かつ必要なもので、プログラミングに新しいですし、私はこのコードを見つけたが、すぐに私はエラーを実行してヒットとしてやってきXCode 6.4
とswift 1.2
を使用しています。
ご協力ありがとうございます。
あなたはどのバージョンのスイフトを使用していますか? –
本当にありがとうございました。 –