Two Alert Views in One View Controller - buttonIndex Response

前端 未结 4 1145
日久生厌
日久生厌 2021-01-13 06:01

I am trying to perform the smile task of having two alerts in a single View Controller. The code below works fine, but how would I make another instance of it elsewhere in t

4条回答
  •  悲哀的现实
    2021-01-13 06:26

    You can use the tag property on UIAlertView to decipher which alert is which:

    -(void)alertChoice
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
        message:@"Message" delegate:self
        cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil];
        alert.tag = 0;
        [alert show];
    }
    
    -(void)alertChoice1
    {
        UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Title"
        message:@"Message" delegate:self
        cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil];
        alert1.tag = 1;
        [alert1 show];
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if(alertView.tag == 0)
        {
        }
    }
    

提交回复
热议问题