如何检查UITextfield是否为空字符串

时间:2015-08-06 15:55:48

标签: ios objective-c cocoa-touch uitextfield

我正在尝试为应用构建登录页面。测试登录条件时出错了。 有两个文本字段usernamepassword。单击“登录”按钮后,警报会显示

1)两个字段都是空的 2)都填补了。

代码反映了以下内容。但结果出来了,无论文本字段是否为空,它只显示文本字段被填充(只有其他部分运行)。所以我认为if条件有问题。但是当我在其他视图中检查if条件时,它起作用了。

有人可以帮忙吗?

if ([_pLoginIDField.text isEqualToString:@""] || [_pPasswordField.text isEqualToString:@""]) {

    UIAlertView *error = [[UIAlertView alloc] initWithTitle:@"Yeah !" message:@"must complete all fields" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [error show];
}
else {
    UIAlertView *error2 = [[UIAlertView alloc] initWithTitle:@"Oooops !" message:@"hhhhhhhhhh" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [error2 show];
}

1 个答案:

答案 0 :(得分:0)

试试这个:

if (_pLoginIDField.text.length > 0 || _pPasswordField.text.length > 0)
相关问题