将对象nil传递到第二个视图



我有一个CalendarView,我已经把对象传递给了另一个带有tableView的UIView。

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

我不知道为什么我的对象是nil在另一个视图

Severo在评论中说,确保你记录每一步。区域设置也存在问题,您需要设置正确的区域设置GB,并且区域对日期有不同的解释。例如:

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;

相关内容

最新更新