I'm trying to detect when a verification code is entered into a text field, so like if I wanted someone to type in "this is a test.", it would then run the following code:
我正在尝试检测何时将验证码输入到文本字段中,如果我想要有人输入“这是一个测试”,那么它将运行以下代码:
system("say this is a test");
But I keep getting the error "void value not ignored as it ought to be". I have no idea what this means. This is what I have so far, but I think I need some other help in which I'll explain below the code.
但我一直得到错误“无法忽视虚空价值,因为它应该是”。我不知道这是什么意思。这是我到目前为止所做的,但我想我需要一些其他帮助,我将在下面解释代码。
if ([SpecialCodeTextField setStringValue:[@"this is a test." stringValue]])
{
system("say this is a test");
}
But if I did something on the iPhone SDK, I could do something like:
但如果我在iPhone SDK上做了一些事情,我可以这样做:
if (MyTextField.text = @"this is a test")
{
[firstView setHidden:YES];
[secondView setHidden:NO];
}
Or something like that. So what is * MyTextField.text = @"this is a test" * on the x86_64 architecture, or when programming for Mac? I'll do a little school equation for you here:
或类似的东西。那么什么是* MyTextField.text = @“这是x86_64架构上的测试”*,还是为Mac编程?我会在这里为你做一个小学校方程式:
MyTextField.text = @"this is a test";
is to Changing textfield text on an iPhone
MyTextField.text = @“这是一个测试”;是在iPhone上更改文本字段文本
as
如
???????????????????????????? is to Changing textfield text on a Mac
????????????????????????????是在Mac上更改文本字段文本
1 个解决方案
#1
1
First of all take a look into the documentation of NSControl
. In your first example you are messaging a NSControl
to set a string value. (BTW. when you use the @"Whatever String"
notation you implicitly create a static NSString
object, so there is no need to call stringValue
).
首先来看看NSControl的文档。在第一个示例中,您将向NSControl发送消息以设置字符串值。 (顺便说一下。当你使用@“Whatever String”符号时,你隐式创建一个静态NSString对象,所以不需要调用stringValue)。
However, the documentation for -setStringValue:
says that the message returns void
, but your if
structure expects any value to check.
但是,-setStringValue:的文档说消息返回void,但if结构需要检查任何值。
In your second example, your code does two things. 1.) It assigns the text member of MyTextField @"this is a test". 2.) The if structure tests the text for nil.
在第二个示例中,您的代码执行两项操作。 1.)它指定MyTextField的文本成员@“这是一个测试”。 2.)if结构测试文本为零。
What exactly do you want? If you want to check the NSTextField
if its not nil
, you would do something like this
你到底想要什么?如果你想检查NSTextField,如果它不是nil,你会做这样的事情
if([specialCodeTextField stringValue]){
...
}
If you want to check if the textValue
in your NSTextField
contains "this is a test" you would do something like this:
如果要检查NSTextField中的textValue是否包含“这是一个测试”,您可以执行以下操作:
if([[specialCodeTextField stringValue] isEqualToString:@"this is a test"]) {
...
}
#1
1
First of all take a look into the documentation of NSControl
. In your first example you are messaging a NSControl
to set a string value. (BTW. when you use the @"Whatever String"
notation you implicitly create a static NSString
object, so there is no need to call stringValue
).
首先来看看NSControl的文档。在第一个示例中,您将向NSControl发送消息以设置字符串值。 (顺便说一下。当你使用@“Whatever String”符号时,你隐式创建一个静态NSString对象,所以不需要调用stringValue)。
However, the documentation for -setStringValue:
says that the message returns void
, but your if
structure expects any value to check.
但是,-setStringValue:的文档说消息返回void,但if结构需要检查任何值。
In your second example, your code does two things. 1.) It assigns the text member of MyTextField @"this is a test". 2.) The if structure tests the text for nil.
在第二个示例中,您的代码执行两项操作。 1.)它指定MyTextField的文本成员@“这是一个测试”。 2.)if结构测试文本为零。
What exactly do you want? If you want to check the NSTextField
if its not nil
, you would do something like this
你到底想要什么?如果你想检查NSTextField,如果它不是nil,你会做这样的事情
if([specialCodeTextField stringValue]){
...
}
If you want to check if the textValue
in your NSTextField
contains "this is a test" you would do something like this:
如果要检查NSTextField中的textValue是否包含“这是一个测试”,您可以执行以下操作:
if([[specialCodeTextField stringValue] isEqualToString:@"this is a test"]) {
...
}