Two Alert Views in One View Controller - buttonIndex Response

前端 未结 4 1142
日久生厌
日久生厌 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:21

    Simply set a tag to each Alert view and check which one sent the messeg.

    alertView.tag=0;
    

    And then

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if(alertView.tag==0){
    
          if(buttonIndex == 0)//OK button pressed
         {
           //do something
         }
         else if(buttonIndex == 1)//Annul button pressed.
         {
          //do something
         }
    }else{
    
      if(buttonIndex == 0)//OK button pressed
    
           {
            //do something
          }
          else if(buttonIndex == 1)//Annul button pressed.
        {
        //do something
        }
      }
    

提交回复
热议问题