-5

My question may be simple for some to answer, but I'm relatively new to Objective C and Xcode. So I have a UILabel and I am running an if statement asking if UILabel is equal to self.NSString then do ... Here is the code.

if (UILabel.text == self.NSString)
{
//Do Something here...
}

I'm wondering if this would work, or what I have to do in order for this to start working. Thanks in advance.

4

2 回答 2

5

使用类中的isEqualToString:方法NSString

if([text isEqualToString:string])
{
  // Do something here.
}
于 2013-07-20T23:38:16.337 回答
1

比较字符串时,您应该使用

[UILabel.text isEqualToString:self.NSString]

== 只是比较指针,即使它们的内容相同,它们通常也会不同。isEqualToString 方法比较内容。

于 2013-07-20T23:42:02.897 回答