Objective c 检查文本字段是否为空 [英] Objective c checking whether text field is empty
本文介绍了Objective c 检查文本字段是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码如下:
- (IBAction) charlieInputText:(id)sender {
//getting value from text field when entered
charlieInputSelf = [sender stringValue];
if (charlieInputSelf != @"") {
//(send field if not empty
}
}
即使该字段为空,它也会发送它;因此,这并不如我所愿.
This sends it even when the field is empty; therefore, this does not work as I want it to.
推荐答案
只检查 nil 和 text length 的长度是否大于 0 - 不为空
Simply checks for nil and if length of text length is greater than 0 - not empty
if (textField.text && textField.text.length > 0)
{
/* not empty - do something */
}
else
{
/* what ever */
}
这篇关于Objective c 检查文本字段是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文