user1525984
user1525984

Reputation:

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. 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];
    }

}

Upvotes: 0

Views: 65

Answers (2)

s.bandara
s.bandara

Reputation: 5664

In addition to what @Tim just said, you have 04 jan lower case where it should be 04 Jan. So use isEqualToString and compare to 04 Jan instead.

Upvotes: 0

Tim
Tim

Reputation: 43354

You should compare strings using isEqualToString, not ==

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

Upvotes: 1

Related Questions