ユーザーがactionSheetのcancelButtonまたは破壊ボタンを押したかどうかを検出しようとしています。彼/彼女の入力に応じて、画面に表示されるアラートメッセージを変更したいと思います。
そこで、を使っif
て確認してみましたが、ユーザーからの入力によって値が変わらないことがわかりましたbuttonIndex
。buttonIndex
UIActionSheet *informUser = [[UIActionSheet alloc] initWithTitle:@"Missing data" delegate:self cancelButtonTitle:@"Thanks for telling me!" destructiveButtonTitle:@"I have ignored it!" otherButtonTitles:nil];
[informUser showInView:self.view];
// NSLog(@"Cancel button = %d", informUser.cancelButtonIndex);
// NSLog(@"Destructive button = %d", informUser.destructiveButtonIndex);
if(informUser.cancelButtonIndex == 1)
{
NSString *msg = [[NSString alloc] initWithFormat:@"Pls enter the number."];
UIAlertView *alertUser = [[UIAlertView alloc] initWithTitle:@"Missing data" message:msg delegate:self cancelButtonTitle:@"Thanks!" otherButtonTitles:nil];
[alertUser show];
}
また、別の方法を使用してみました。
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;
UIAlert
しかし、同じ画面の異なるポイントに複数あると、間違った結果が得られます。
UIAlert
要するに、ユーザーからのアクション/入力ごとに異なるものを使用したいと思います。したがって、のどのボタンがユーザーによって押されたかを検出するにはどうすればよいactioSheet
ですか?
ありがとうございました。