相等的字符串不相等? [英] Equal strings not equal?

查看:55
本文介绍了相等的字符串不相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
理解 Objective-C 中的 NSString 比较

我在 Objective-c 中遇到了奇怪的事情,我试图将 cell.label 与元素 title 进行比较,它是字符串.识别我正在寻找的单元格.

I'v encountered strange things in objective-c, I'm trying to compare cell.label with elements title which is string. to identify whever it is a cell I am looking for.

NSLog(@"%@", cell.textLabel.text);
NSLog(@"%@", [_dropDownSelection1.elements[1] title]);
if(cell.textLabel.text == [_dropDownSelection1.elements[1] title]){
    NSLog(@"Positive");
}
else{
    NSLog(@"Negative");
}

NSLog 打印出两者中的文本完全相同,但我仍然总是以否定结尾...为什么会这样?

NSLog prints that the text in both is exactly the same, but still i always end up with negative... Why is that?

推荐答案

您应该使用 [cell.textLabel.text isEqualToString:[_dropDownSelection1.elements[1] title]] 来比较字符串.

You should use [cell.textLabel.text isEqualToString:[_dropDownSelection1.elements[1] title]] to compare the strings.

这篇关于相等的字符串不相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆