2011-08-11 52 views
0

請問,爲什麼不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 
+0

你爲什麼用'stringWithString'而不是''[passwo.text isEqualToString:globalpassword]''來煩惱? – deanWombourne

+0

我嘗試比較UIText字段和我的globalpassord但不工作 –

+0

編輯您的問題並添加一些有關錯誤的信息 - 崩潰了嗎? – deanWombourne

回答

2

看看你的NSLog行;它應該是這樣的:

NSLog(@"hi all freind"); 

(注意@符號!)


編輯這一定意味着你忽略你的編譯器警告!他們在那裏是有原因的;在這種情況下,告訴你,你正在向NSLog傳入錯誤的參數。

我敢打賭,你也會在NSLog(cc)NSLog(bb)行上發出警告嗎?

+0

哦,很好的觀察! –

+0

其實,我更喜歡你的答案 - 編譯器可以修復我看到的錯誤,但它需要經驗來修復你捕獲的錯誤;) – deanWombourne

+0

好吧,我糾正它們,但我不能比較我的UITextFIled中的值 –

2

字符串不同。嘗試登錄BB和CC這樣的:

NSLog(@"bb: '%@', cc: '%@'", bb, cc); 

用單引號就可以看到是否有任何BB或CC意外空白。