Make UIAlertView Button trigger function On Press

后端 未结 7 2060
小蘑菇
小蘑菇 2020-12-25 09:22

Currently I am using the following code to present a UIAlertView:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@\"Today\'s Entry Complete\"
               


        
7条回答
  •  星月不相逢
    2020-12-25 09:46

    Little more clarification,

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
        {
           //handles title you've added for cancelButtonTitle
            if(buttonIndex == [alertView cancelButtonIndex]) {
                //do stuff
            }else{
               //handles titles you've added for otherButtonTitles
                if(buttonIndex == 1) {
                    // do something else
                }
                else if(buttonIndex == 2) {
                    // do different thing
                }
            }
        }
    

    Example,

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Need your action!" 
    message:@"Choose an option to continue!" delegate:self cancelButtonTitle:@"Not Need!" 
    otherButtonTitles:@"Do Something", @"Do Different", nil];
    [alert show];
    

    enter image description here

    (it's iOS7 screenshot)

提交回复
热议问题