我正在编写一个包含多个视图的程序。我想在视图之间传递日期变量。我使用extern NSDate *chooseDate
创建了一个全局变量。我在其中一个视图上声明了变量NSDate *date
。然后我设置date = chooseDate
。然后我使用以下代码添加日期;
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:(int)daycount];
date = [calendar dateByAddingComponents:components toDate:date options:0];
问题似乎是chooseDate
未被识别为NSDate
。代码在date = [calendar ...]
崩溃。我不知道为什么会发生这种情况。我希望我已经清楚地解释了。有任何想法吗?
答案 0 :(得分:0)
您正在将chooseDate
设置为autoreleased
个实例。当你尝试使用它时,你确定它存在吗?您可能需要retain
。
答案 1 :(得分:0)
如果您将chooseDate = [datePicker date];
更改为chooseDate = [[datePicker date] copy];
,可能会有效。如果确实如此,其余的应该是非常自我解释的。