passed object nil into my second view

2019-08-18 20:42发布

I have a CalendarView and I've passed the object to another UIView with a tableView in it.

In my CalendarView:

    anotherView *anotherViewController = [[anotherView alloc] init];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd-MM-yyyy"];
    NSString *dateString = [formatter stringFromDate:aDateObject];
    anotherViewController.eventDate = aDateObject;
    anotherViewController.eventDateTitle = dateString;

    [formatter release];
    [anotherViewController release];

I don't know why my object its nil in anotherView...

1条回答
倾城 Initia
2楼-- · 2019-08-18 21:11

As el.severo says in the comments, ensure you log every step. Also there are issues with locales, you need to set the correct locale GB and us regios have different interpretations of dates. E.g. for US:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd-MM-yyyy"];

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[dateFormatter setLocale:locale];
[locale release];

NSLog(@"date obj:%@", aDateObject); 
NSString *dateString = [formatter stringFromDate:aDateObject];
NSLog(@"date str:%@", dateString); 

anotherViewController.eventDate = aDateObject;
anotherViewController.eventDateTitle = dateString;
查看更多
登录 后发表回答