【问题标题】:textfield text content comparision wont work文本字段文本内容比较不起作用
【发布时间】:2012-09-11 02:23:32
【问题描述】:

我有这段代码:

    if (email.text == emailComfirm.text) {
        UIAlertView *emailAllertView = [[UIAlertView alloc] initWithTitle:@"Succes" message:@"Yaaay, je kan nu gebuik gaan maken van Vogelspotter." delegate:self cancelButtonTitle:@"Direct aanmelden" otherButtonTitles: nil];
        [emailAllertView show];
        // Doing some other code here
        [self dismissModalViewControllerAnimated:YES];
    }else{
        NSLog(@"email: %@", email.text);
        NSLog(@"email: %@", emailComfirm.text);

        UIAlertView *emailAllertView = [[UIAlertView alloc] initWithTitle:@"Foutmelding" message:@"De opgegeven email adressen komen niet met alkaar overeen" delegate:self cancelButtonTitle:@"Probeer het nog eens" otherButtonTitles: nil];
        [emailAllertView show];
    }

不知何故,如果我输入 ee/ee 或 ee/ff,我在 textfiels 中没有输入任何内容,is 语句总是转到 else。谁能告诉我我做错了什么?

tnx 提前。

【问题讨论】:

标签: objective-c xcode ios5


【解决方案1】:

您想使用[email.text isEqualToString:emailComfirm.text] 来比较 2 个 NSString* 对象的内容。使用 == 将比较 2 个对象的地址,而不是对象的内容。这就是指针的工作原理How do pointer to pointers work in C?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    • 2015-08-24
    • 1970-01-01
    • 2013-03-24
    相关资源
    最近更新 更多