1 つの View Controller に 2 つのアラートを設定するというスマイル タスクを実行しようとしています。以下のコードは問題なく動作しますが、View Controller の別の場所に別のインスタンスを作成するにはどうすればよいでしょうか。コードを複製すると、buttonIndex がどのアラートに応答しているかがわからないのではないかと心配しています。何か案は?ありがとう!
-(void)alertChoice
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Message" delegate:self
cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
//do something
}
}