passed object nil into my second view

∥☆過路亽.° 提交于 2019-12-24 23:24:30

问题


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:


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;


来源:https://stackoverflow.com/questions/8270471/passed-object-nil-into-my-second-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!