下記のソースコードは、ボタンを長押しするとアラートが表示されるプログラムです。
しかし、長押ししても1度はアラートが表示されますが、アラートを閉じてまたボタン長押ししても表示されないのです。
さらにログに下記のようなメッセージが表示されます。
解決策をアドバイス頂けると幸いです。
「ログ」
2016-12-20 17:13:17.992 SeBtn[2079:81223] Warning: Attempt to present <UIAlertController: 0x7fb671e9e280> on <ViewController: 0x7fb671c07d90> which is already presenting <UIAlertController: 0x7fb671e1ddc0>
[ViewController.m]
#import "ViewController.h" #import "AppDelegate.h" AppDelegate *ViewAppDelegate; UILongPressGestureRecognizer *LongGesture; @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //ロングタップ開始 [self setLongTapGesture]; //delegateデータを送る準備 ViewAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } //ロングタップ開始 - (void)setLongTapGesture{ LongGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(long_tapped:)]; LongGesture.delegate = self; } //音声アラートname_keep_str1-24 - (void)voice_Alert { //音声名代入 if(_btn1.tag == 1) { ac = [UIAlertController alertControllerWithTitle:@"音声名" message:ViewAppDelegate.name_keep_str1 preferredStyle:UIAlertControllerStyleAlert]; } if(_btn2.tag == 2) { ac = [UIAlertController alertControllerWithTitle:@"音声名" message:ViewAppDelegate.name_keep_str2 preferredStyle:UIAlertControllerStyleAlert];; } if(_btn3.tag == 3) { ac = [UIAlertController alertControllerWithTitle:@"音声名" message:ViewAppDelegate.name_keep_str3 preferredStyle:UIAlertControllerStyleAlert]; } if(_btn4.tag == 4) { ac = [UIAlertController alertControllerWithTitle:@"音声名" message:ViewAppDelegate.name_keep_str4 preferredStyle:UIAlertControllerStyleAlert]; } if(_btn5.tag == 5) { ac = [UIAlertController alertControllerWithTitle:@"音声名" message:ViewAppDelegate.name_keep_str5 preferredStyle:UIAlertControllerStyleAlert]; } // コントローラを生成 // Cancel用のアクションを生成 UIAlertAction * recoAction = [UIAlertAction actionWithTitle:@"録音" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { // ボタンタップ時の処理 }]; UIAlertAction * delAction = [UIAlertAction actionWithTitle:@"削除" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { }]; [ac addAction:recoAction]; [ac addAction:delAction]; // アラート表示処理 [self presentViewController:ac animated:YES completion:nil]; } //ロングタップ - (void)long_tapped:(UILongPressGestureRecognizer *)sender{ //ボタンに応じてアラート表示 //btn1 if(_btn1.tag == 1) { [self voice_Alert]; } //btn2 if(_btn2.tag == 2) { [self voice_Alert]; } //btn3 if(_btn3.tag == 3) { [self voice_Alert]; } //btn4 if(_btn4.tag == 4) { [self voice_Alert]; } //btn5 if(_btn5.tag == 5) { [self voice_Alert]; } } //action btn1-24 - (IBAction)btn1:(id)sender { //ロングタップ有効化 //btn に追加 [_btn1 addGestureRecognizer:LongGesture]; _btn1.userInteractionEnabled = YES; } - (IBAction)btn2:(id)sender { [_btn2 addGestureRecognizer:LongGesture]; _btn2.userInteractionEnabled = YES; } - (IBAction)btn3:(id)sender { [_btn3 addGestureRecognizer:LongGesture]; _btn3.userInteractionEnabled = YES; } - (IBAction)btn4:(id)sender { [_btn4 addGestureRecognizer:LongGesture]; _btn4.userInteractionEnabled = YES; } - (IBAction)btn5:(id)sender { [_btn5 addGestureRecognizer:LongGesture]; _btn5.userInteractionEnabled = YES; } @end
[ViewController.h]
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIGestureRecognizerDelegate,UIAlertViewDelegate> { // アラートコントローラを生成 UIAlertController * ac; } //ロングタップ - (void)long_tapped:(UILongPressGestureRecognizer *)sender; //ロングタップ開始 - (void)setLongTapGesture; //音声アラート - (void)voice_Alert; @end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/12/20 08:45