简体   繁体   English

无法执行搜寻

[英]Can't perform segue

I Have two views, one with two buttons and a pickerview, and other with some text... One of the buttons in the first view is the "TODAY" button, then there's the picker view with all the year's days, and then theres another button, "CHOOSE", the second button get's the date chosen on the pickerview and takes us to next view by a modal segue with identifier "mySegue", and show personalized content acording to the day chosen. 我有两个视图,一个带有两个按钮和一个pickerview,另一个带有一些文本...第一个视图中的一个按钮是“ TODAY”按钮,然后是一整年的选择器视图,然后是另一个按钮“ CHOOSE”,第二个按钮获取在pickerview上选择的日期,并通过带有标识符“ mySegue”的模态segue带我们进入下一个视图,并显示与所选日期对应的个性化内容。 The first button is supposed to get todays date and take us to next view with personalized content for the days date. 第一个按钮应该获取今天的日期,并带我们进入日期日期个性化内容的下一个视图。 But I can't get it to work with my code! 但是我无法使其与我的代码一起使用! I Tried to explain it the best i could... 我试图尽我所能解释一下...

-(IBAction)today:(id)sender{

    NSDate *date = [NSDate date];

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];

    [dateFormat setDateFormat:@"dd MMM"];

    NSString *dateString = [dateFormat stringFromDate:date];

    test.text = dateString;

    if (dateString == @"04 jan") {

        [self performSegueWithIdentifier:@"mySegue" sender:self];
    }

}

You should compare strings using isEqualToString , not == 您应该使用isEqualToString比较字符串,而不是==

if([dateString isEqualToString:@"04 jan"]){
    ...
}

In addition to what @Tim just said, you have 04 jan lower case where it should be 04 Jan . 除了什么@Tim刚才说的,你有04 jan较低的情况下应该是04 Jan So use isEqualToString and compare to 04 Jan instead. 因此,请使用isEqualToString并将其与04 Jan进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM