标签基于星期几

时间:2013-12-19 21:12:51

标签: objective-c string-comparison

我正在尝试根据星期几显示欢乐时光特价,但由于某种原因,标签与当前日期不匹配。我对Xcode很新,所以我不确定我是否忽略了什么......这是我的代码:

NSDate *today = [NSDate date];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"EEEE"];
    NSString *dateString = [dateFormat stringFromDate:today];
    NSLog(@"date: %@", dateString);
    lblTitle.text = pawpost.title;
    lblPhone.text = pawpost.phone;
    if ((dateString = @"Thursday")) {
        happy.text = pawpost.thu;
    }
    else if ((dateString = @"Monday")) {
        happy.text = pawpost.mon;
    }
    else if ((dateString = @"Tuesday")) {
        happy.text = pawpost.tue;
    }
    else if ((dateString = @"Wednseday")) {
        happy.text = pawpost.wed;
    }
    else if ((dateString = @"Friday")) {
        happy.text = pawpost.fri;
    }
    else if ((dateString = @"Saturday")) {
        happy.text = pawpost.sat;
    }
    else if ((dateString = @"Sunday")) {
        happy.text = pawpost.sun;
    }

1 个答案:

答案 0 :(得分:2)

您需要使用isEqualToString:方法:

if([dateString isEqualToString:@"Monday"]) {
    happy.text = pawpost.mon;
}

您可能还希望本地化@"Monday"字符串文字。