Detecting button click with UIAlertView

后端 未结 6 1264
难免孤独
难免孤独 2021-01-01 12:10

I am trying to call and alert when a button is pressed. i use this :

-(IBAction)Add { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @\"add bu         


        
6条回答
  •  轮回少年
    2021-01-01 12:33

    1)
    .h file 
    @interface MyClassViewController: 
    
    2)
    .m file
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Note"
                                                    message:@"some message"
                                                   delegate:self    // must be self to call clickedButtonAtIndex
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:@"OK", nil];
    
    
    3)
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
      if (buttonIndex == [alertView cancelButtonIndex]) {
        NSLog(@"The cancel button was clicked from alertView");
      }
     else {
    
    }
    }
    

提交回复
热议问题