我只是在比较两个字符串的值。。我已经创建了一个Python脚本服务器,从中获取一个值,另一个值是本地字符串变量。我可以从服务器上检索正确的值,但是在比较时它不会进入循环。。在
这是我在客户机中比较值的代码
-(void)messageReceived:(NSString *)message {
[_messages addObject:message];
NSLog(@"the received message is %@",message);
if (message == @"1")
NSLog(@"the user is online");
else if (message == @"0") {
UIAlertView *alert;
alert = [[UIAlertView alloc]initWithTitle:@"Message" message:@"The selected user is not online !" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles: nil];
[alert show];
}
}
这是一个日志,我可以看到正确的值
2012-02-25 21:44:35.376 iMessenger[2001:207]服务器称:1 2012-02-25 21:44:35.377 iMessenger[2001:207]收到的消息是1
有人能告诉我怎么回事吗。。谢谢
您可以使用caseInsensitiveCompare
不要使用==来比较字符串。请改用
[message isEqualToString:@"1"]
。在使用isEqualString比较NSString值:
相关问题 更多 >
编程相关推荐