将对象nil传递给我的第二个视图 [英] passed object nil into my second view

查看:78
本文介绍了将对象nil传递给我的第二个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CalendarView,我已将该对象传递给另一个带有tableView的UIView。

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

在我的CalendarView中:

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...

推荐答案

正如el.severo在评论中所说,确保您记录每一步。 区域设置也存在问题,您需要设置正确的语言环境GB和我们的regios对日期有不同的解释。例如。 for US:

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;

这篇关于将对象nil传递给我的第二个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆