【问题标题】:How to turn off dismiss UIAlertView when click UIButton in alert view在警报视图中单击 UIButton 时如何关闭关闭 UIAlertView
【发布时间】:2014-12-08 08:11:12
【问题描述】:

单击 UIAlertView 中的按钮时关闭关闭 UIAlertView 的正确方法是什么。当单击按钮不关闭视图时,我想检查 UITextField 中是否没有字符串。

  -(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
            }
        }

    }

【问题讨论】:

标签: ios objective-c


【解决方案1】:

不验证字符串验证文本字段

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

编辑

你也可以试试:

if ([emailInputTextField.text length] != 0) {
//Do something
}
else {
//All fields are required UIAlert here
}

【讨论】:

  • 我尝试了,但单击按钮时 alertview 仍然关闭
  • @apple8 看到我的编辑。无论哪种方式,它都是查找空文本字段的正确方法。你只需要正确嵌套它们
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-05
  • 2012-09-03
  • 2017-11-26
  • 2020-02-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多