0

What is correct way to turn off dismiss UIAlertView when click button in UIAlertView. I want to check if not have string in UITextField when click button not dismiss the view.

  -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
      //Add alert delegate
    if (alertView.tag == kDeleteAlertTag)
    {

        if (buttonIndex == 0)
        {
            [self.emails removeObjectAtIndex:currentIndex];
            [self.plistReader saveToPlistName:kPlistEmails fromArray:self.emails];
            [self.tblEmails reloadData];
        }
    }

    // remove email alert delegate
    if (alertView.tag == kAddEmailTag)
    {
        if (buttonIndex == 0)
        {

            // get text Input Alert
            UITextField * emailInputTextField = [alertView textFieldAtIndex:0];

            // get string from text Alert
            NSString *textInput = [emailInputTextField text];

            if (self.emails== nil) {
                self.emails = [[NSMutableArray alloc]init];
            }
            if ([textInput isEqualToString:@""]) {
                NSLog(@"Not have string");
            }else
            if ([KUtils NSStringIsValidEmail:textInput] == YES)
            {
                [self.emails addObject:textInput];

                // save to plist and reload table
                [self.plistReader saveToPlistName:kPlistEmails fromArray:self.emails];
                [self.tblEmails reloadData];

            }else if([KUtils NSStringIsValidEmail:textInput] == NO)
            {

                // not dismiss alert in hre
            }
        }

    }
John Saunders
  • 160,644
  • 26
  • 247
  • 397
apple8
  • 33
  • 8

1 Answers1

0

Don't validate against the string validate against the text field

 if (emailInputTextField.text && emailInputTextField.text.length > 0)
{
//do something 
}
else
{
//All fields are required UIAlert here
}

Edit

You can also try:

if ([emailInputTextField.text length] != 0) {
//Do something
}
else {
//All fields are required UIAlert here
}
soulshined
  • 9,612
  • 5
  • 44
  • 79