比较NSString使用isEqualToString
请问,为什么不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
看看你的NSLog行;它应该是这样的:
NSLog(@"hi all freind");
(注意@符号!)
编辑这一定意味着你忽略你的编译器警告!他们在那里是有原因的;在这种情况下,告诉你,你正在向NSLog传入错误的参数。
我敢打赌,你也会在NSLog(cc)
和NSLog(bb)
行上发出警告吗?
哦,很好的观察! –
其实,我更喜欢你的答案 - 编译器可以修复我看到的错误,但它需要经验来修复你捕获的错误;) – deanWombourne
好吧,我纠正它们,但我不能比较我的UITextFIled中的值 –
字符串不同。尝试登录BB和CC这样的:
NSLog(@"bb: '%@', cc: '%@'", bb, cc);
用单引号就可以看到是否有任何BB或CC意外空白。
你为什么用'stringWithString'而不是''[passwo.text isEqualToString:globalpassword]''来烦恼? – deanWombourne
我尝试比较UIText字段和我的globalpassord但不工作 –
编辑您的问题并添加一些有关错误的信息 - 崩溃了吗? – deanWombourne