iosアプリ作成をしていて、uitableviewを使用したページがあるのですが、
そちらでpresentの第一引数にalertControllerを設定して、
そのセルが押された際に、アラートが表示され「はい、いいえ」どちらかを選び初めて
画面遷移するような仕様にしていると、
タップしてからアラートが出るまでとても時間がかかったり、
そうかと思えば2回タップするとすぐに表示されたりする現象で悩まされていました。
するとリンク内容こちらのサイトに同じような現象が書かれていました。ですが、数年前の記事であること、objective-cであることなどでうまくいきませんでした。
ソースを下記に記載します。
コメントアウト部分の"ここの行"をこのように変えると良いというのを海外のサイトで目にしたので試しましたが、
アラートが出ずに、次の画面に遷移していまいそこで落ちてしまいます。
解決策を知っている方はおられないでしょうか?
DispatchQueue.main.async { self.present(alertController, animated: true, completion: nil) }
func tableView(_ table: UITableView, didSelectRowAt indexPath: IndexPath) { if status[indexPath.row] == 0 { print("アイウエオ") let alertController = UIAlertController(title: "", message: "遷移しますか?", preferredStyle: UIAlertControllerStyle.alert) let actionOK = UIAlertAction(title: "OK", style: UIAlertActionStyle.default ,handler:{ (action:UIAlertAction!) -> Void in self.appDelegate.id = self.user_id[indexPath.row] //この行追加 let storyboard:UIStoryboard = self.storyboard! let lp = storyboard.instantiateViewController(withIdentifier: "second") as! SecondViewController lp.modalTransitionStyle = UIModalTransitionStyle.partialCurl self.navigationController?.pushViewController(lp, animated: true) }) let cancelAction:UIAlertAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler:{ (action:UIAlertAction!) -> Void in print("Cancel") }) alertController.addAction(actionOK) alertController.addAction(cancelAction) self.present(alertController, animated: true, completion: nil)//ここの行 }else{ print("カキクケコ") //ここから追加部分 self.appDelegate.id = self.user_id[indexPath.row] let storyboard:UIStoryboard = self.storyboard! let lp = storyboard.instantiateViewController(withIdentifier: "second") as! SecondViewController lp.modalTransitionStyle = UIModalTransitionStyle.partialCurl self.navigationController?.pushViewController(lp, animated: true) } }
回答1件
あなたの回答
tips
プレビュー