私は迅速かつXcodeの初心者ですので、おそらく本当に乱雑なコードを許してください! 私は次の警告を得る私のコードを実行している場合: 警告:その上で提示する試みは、すでに私はすでにフォーラムをチェックし、その問題に関する記事を発見した警告:UIAlertControllerは既に提示しています
を提示しているが....私は助けをのように示唆した適用:
if presentedViewController !== nil {
self.presentViewController(alertController, animated: true, completion: nil)
} else{
self.dismissViewControllerAnimated(false, completion: nil)
self.presentViewController(alertController, animated: true, completion: nil)
}
しかし、それでも私には同じ警告が与えられます。だから私はそこに何か間違ったことをしたに違いないと思います。誰かが私は私のコードまで「きれいに」することができますどのようになどの任意の提案が高く評価されている場合:)また:)してください私を助けることができればそれは素晴らしいことだ
あなたはこのようなあなたのコード、存在を変更する必要がimport UIKit
class ViewController: UIViewController {
@IBOutlet var Label: UILabel!
@IBOutlet var ukFlag: UITextView!
@IBOutlet var movie: UITextView!
@IBOutlet var piano: UITextView!
@IBOutlet var book: UITextView!
@IBOutlet var dance: UITextView!
@IBOutlet var paint: UITextView!
@IBOutlet var row: UITextView!
@IBOutlet var envelope: UITextView!
@IBOutlet var dragon: UITextView!
@IBOutlet var instagram: UITextView!
func londonPuzzle(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
self.ifCollided()
}
func misleadOne(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
self.ifCollided()
}
func bestival(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
self.ifCollided()
}
func rosieProject(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
self.ifCollided()
}
func misleadTwo(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
self.ifCollided()
}
func misleadThree(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
self.ifCollided()
}
func misleadFour(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
self.ifCollided()
}
func voucher(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
self.ifCollided()
}
func welsh(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
self.ifCollided()
}
func hulk(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y)
sender.setTranslation(CGPointZero, inView: self.view)
self.ifCollided()
}
func ShowAlertWrong(){
let alertController = UIAlertController(title: "Sorry", message: " Guess again!", preferredStyle: .Alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) {
UIAlertAction in
self.ukFlag.center = CGPointMake(150, 225)
self.movie.center = CGPointMake(150, 225)
self.piano.center = CGPointMake(150, 225)
self.dance.center = CGPointMake(150, 225)
self.paint.center = CGPointMake(150, 225)
self.row.center = CGPointMake(150, 225)
self.envelope.center = CGPointMake(150, 225)
self.dragon.center = CGPointMake(150, 225)
self.instagram.center = CGPointMake(150, 225)
}
let resetAction = UIAlertAction(title: "Reset", style: UIAlertActionStyle.Default) {
UIALertAction in
self.ukFlag.center = CGPointMake(150, 225)
self.movie.center = CGPointMake(150, 225)
self.piano.center = CGPointMake(150, 225)
self.dance.center = CGPointMake(150, 225)
self.paint.center = CGPointMake(150, 225)
self.row.center = CGPointMake(150, 225)
self.envelope.center = CGPointMake(150, 225)
self.dragon.center = CGPointMake(150, 225)
self.instagram.center = CGPointMake(150, 225)
}
alertController.addAction(okAction)
alertController.addAction(resetAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
func ShowAlertWin(){
let alertController = UIAlertController(title: "Congrats", message: " You are correct!", preferredStyle: .Alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) {
UIAlertAction in
self.book.center = CGPointMake(150, 150)
}
/* let resetAction = UIAlertAction(title: "Reset and hope the mood has changed", style: UIAlertActionStyle.Default) {
UIALertAction in
self.Angry.center = CGPointMake(150, 150)
}*/
alertController.addAction(okAction)
// alertController.addAction(resetAction)
if presentedViewController !== nil {
self.presentViewController(alertController, animated: true, completion: nil)
} else{
self.dismissViewControllerAnimated(false, completion: nil)
self.presentViewController(alertController, animated: true, completion: nil)
}
}
@IBAction func ifCollided(){
if CGRectIntersectsRect(Label.frame, ukFlag.frame) {
ShowAlertWrong()
}
else if CGRectIntersectsRect(Label.frame, movie.frame){
ShowAlertWrong()
} else if CGRectIntersectsRect(Label.frame, piano.frame){
ShowAlertWrong()
} else if CGRectIntersectsRect(Label.frame, dance.frame){
ShowAlertWrong()
} else if CGRectIntersectsRect(Label.frame, paint.frame){
ShowAlertWrong()
} else if CGRectIntersectsRect(Label.frame, row.frame){
ShowAlertWrong()
} else if CGRectIntersectsRect(Label.frame, envelope.frame){
ShowAlertWrong()
} else if CGRectIntersectsRect(Label.frame, dragon.frame){
ShowAlertWrong()
} else if CGRectIntersectsRect(Label.frame, instagram.frame){
ShowAlertWrong()
} else if CGRectIntersectsRect(Label.frame, book.frame){
ShowAlertWin()
}
}
override func viewDidLoad() {
super.viewDidLoad()
ukFlag.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.londonPuzzle(_:))))
movie.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.misleadOne(_:))))
piano.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.bestival(_:))))
book.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.rosieProject(_:))))
dance.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.misleadTwo(_:))))
paint.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.misleadThree(_:))))
row.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.misleadFour(_:))))
envelope.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.voucher(_:))))
dragon.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.welsh(_:))))
instagram.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.hulk(_:))))
}
}
ねえ、おかげで現在の呼び出しを行う上部可視のViewControllerを取得するために、ヘルパーfuncを作成 !しかし、それは警告ウィンドウが本当に素早く2回ポップアップするように思われます...私はそれを修正しようとしましたが、どのように...それが何回ループに入るか何かを持っているのか分かりません。 – CatiaV5
もう少し説明できますか? –
ラベル上に正しいシンボルをドラッグ・ドロップすると、アラート・ボックスが連続して2回連続して表示されます(アラート「間違っている」というメッセージが表示されてすぐにシャットダウンし、再度ポップアップします)。私の説明は今より意味が分かりますか?それは説明するのが本当に難しいです...それはすぐに開く、閉じるとすぐに開く。 – CatiaV5