Make UIAlertView Button trigger function On Press

后端 未结 7 2043
小蘑菇
小蘑菇 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:38

    You need to set the delegate when allocating the alertview, then use one of the UIAlertViewDelegate methods to call your own method, for example:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Today's Entry Complete"
                                                    message:@"Press OK to submit your data!"
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];
    
    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
    {
        [self submitData];
    }
    

提交回复
热议问题