使用 isEqualToString 比较 NSString

发布于 2024-11-29 03:39:06 字数 993 浏览 0 评论 0原文

请问,为什么 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

极度宠爱 2024-12-06 03:39:06

看看你的 NSLog 行;它应该看起来像这样:(

NSLog(@"hi all freind");

注意@符号!)


编辑这一定意味着您忽略了编译器警告!他们在那里是有原因的;在这种情况下,告诉您向 NSLog 传递了错误的参数。

我敢打赌您也会在 NSLog(cc)NSLog(bb) 行上收到警告?

Take a look at your NSLog line; it should look like this :

NSLog(@"hi all freind");

(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) and NSLog(bb) lines as well?

醉梦枕江山 2024-12-06 03:39:06

字符串不同。尝试像这样记录 bb 和 cc:

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

使用单引号,您可以查看 bb 或 cc 中是否存在意外的空格。

The strings differ. Try logging bb and cc like this:

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

With the single quotes you can see whether there is unexpected whitespace in either bb or cc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文