我有一个带有日期选择器的视图控制器,并将变量设置为选择的日期。
当我关闭视图控制器时,变量为空。
有什么建议么?
按下“完成”时的 DatePickerView 代码(NSLogs 显示将日期分配给变量):
-(void)done:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
AddEditFixturesTableViewController *fixtures = [[AddEditFixturesTableViewController alloc]init];
fixtures.fixtureDateTime = pickerDateTime;
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"dd-MM-yyyy"];
NSString *pickerDateTimeString = [formatter stringFromDate:pickerDateTime];
NSLog(@"Picker Date: %@", pickerDateTimeString);
NSString *fixturesDateTimeString = [formatter stringFromDate:[fixtures fixtureDateTime]];
NSLog(@"Fixture Date: %@", fixturesDateTimeString);
}
当我检查是否分配了日期时的代码(NSLogs 显示变量为空):
DatePickViewController *pickerView = [[DatePickViewController alloc]init];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"dd-MM-yyyy"];
NSString *fixturesDateTimeString = [formatter stringFromDate:fixtureDateTime];
NSLog(@"Fixture Date: %@", fixturesDateTimeString);
NSString *pickerDateTime = [formatter stringFromDate:[pickerView pickerDateTime]];
NSLog(@"Picker Date: %@", pickerDateTime);