使用 isEqualToString 比较 NSString
请问,为什么 isEqualToString
不起作用?
- (void)viewDidLoad {
[super viewDidLoad];
extern NSString* globalpassword;
if ([passwo.text isEqualToString: globalpassword]) {
res = [[XMLTestViewController alloc] initWithNibName:@"XMLTestViewController" bundle:nil];
res.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.view addSubview:res.view];
} else {
NSLog(@"faux");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"chikos"
message:@"Wrong Password" delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
}
the result is
2011-08-11 17:56:36.543 XMLTest[6389:207] pol
2011-08-11 17:56:36.544 XMLTest[6389:207] pol
2011-08-11 17:56:36.544 XMLTest[6389:207] faux
Please, why doesn't isEqualToString
work?
- (void)viewDidLoad {
[super viewDidLoad];
extern NSString* globalpassword;
if ([passwo.text isEqualToString: globalpassword]) {
res = [[XMLTestViewController alloc] initWithNibName:@"XMLTestViewController" bundle:nil];
res.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.view addSubview:res.view];
} else {
NSLog(@"faux");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"chikos"
message:@"Wrong Password" delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
}
the result is
2011-08-11 17:56:36.543 XMLTest[6389:207] pol
2011-08-11 17:56:36.544 XMLTest[6389:207] pol
2011-08-11 17:56:36.544 XMLTest[6389:207] faux
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看你的 NSLog 行;它应该看起来像这样:(
注意@符号!)
编辑这一定意味着您忽略了编译器警告!他们在那里是有原因的;在这种情况下,告诉您向 NSLog 传递了错误的参数。
我敢打赌您也会在
NSLog(cc)
和NSLog(bb)
行上收到警告?Take a look at your NSLog line; it should look like this :
(notice the @ sign!)
EDIT This must mean that you're ignoring your compiler warnings! They're there for a reason; in this case, telling you that you're passing in the wrong parameter to NSLog.
I bet you're also getting warnings on the
NSLog(cc)
andNSLog(bb)
lines as well?字符串不同。尝试像这样记录 bb 和 cc:
使用单引号,您可以查看 bb 或 cc 中是否存在意外的空格。
The strings differ. Try logging bb and cc like this:
With the single quotes you can see whether there is unexpected whitespace in either bb or cc.