1

I have problem on alertview when I am trying to display some text if the user cancel the alertivew.

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
    UIALertView alertview = [[UIAlertView alloc] initWithTitle:@"New Answer"
                                             message:@"Your text"
                                                  delegate:self
                                                  cancelButtonTitle:@"Cancel"
                                                  otherButtonTitles:@"OK", nil];

    [alert show]

    if (buttonIndex == 0)
    {
        NSLog(@"ok");
        [[self sectionSelectedDisplay] setText:answerLabel];
    }
    else
    {
        NSLog(@"cancel");
    }
}

+++++++++++++++++++++++++

Can anyone help me fix this issue?

4
  • 1
    So you want to NSlog the index of the alertview button pressed?
    – Woodstock
    Aug 21, 2013 at 7:22
  • The issue is not clear. What do you exactly need help for? Aug 21, 2013 at 7:23
  • @Puneet: I edited the code. That my function. this [[self sectionSelectedDisplay] setText:answerLabel]; is notworking inside the if statement.
    – Aragon
    Aug 21, 2013 at 9:43
  • Because I want to run the code [[self sectionSelectedDisplay] setText:answerLabel]; after the user press "OK"
    – Aragon
    Aug 21, 2013 at 9:45

1 Answer 1

1

there is a function in UIalertviewdelegate as

if you have two button then function works as follows

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   if (buttonIndex == 1) {
      // this is normal button 
   }    
   else if (buttonIndex == 0) {
      // this is cancel button 
   }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.