当我在我的应用程序中去看看控制器时,我有两个日期选择器。两者都有标签,如果任何一个被移动,他们会相应地更新。用户界面日期选择器不显示在标签
开始日期被设置为自动成为今天的日期。虽然它保存到Core Data就好了,但它不会显示在标签中,除非我将其更改为不同的日期。
基本上,当我加载该屏幕的标签应该有今天的日期,如果我在日期选择器中更改它,就会发生变化。
我想这是简单的俯视,但我不明白它是什么,任何帮助将不胜感激。
- (void)viewDidLoad
{
[super viewDidLoad];
svos = self.scrollView.contentOffset;
[self.startDate addTarget:self action:@selector(datePickerChanged:) forControlEvents:UIControlEventValueChanged];
[self.endDate addTarget:self action:@selector(datePickerChanged1:) forControlEvents:UIControlEventValueChanged];
AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
if(!appDelegate.dateProductionDroneStartDate)
[self.startDate setDate:[NSDate date]];
else
{
[self.startDate setDate:appDelegate.dateProductionDroneStartDate];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yyyy "];
NSString *strDate = [dateFormatter stringFromDate:self.startDate.date];
self.productionDroneStartDate.text = strDate;
}
NSDate *now = [NSDate date];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:1];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *newDate2 = [gregorian dateByAddingComponents:components toDate:now options:0];
if(!appDelegate.dateProductionDroneEndDate)
[self.endDate setDate:newDate2];
else
{
[self.endDate setDate:appDelegate.dateProductionDroneEndDate];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yyyy "];
NSString *strDate = [dateFormatter stringFromDate:self.endDate.date];
self.productionDroneEndDate.text = strDate;
}
self.txtProductionName.text = appDelegate.strProductionName;
self.txtProductionScene.text = appDelegate.strProductionScene;
self.txtProductionReel.text = appDelegate.strProductionReel;
self.txtProductionName.delegate = self;
self.txtProductionReel.delegate = self;
self.txtProductionScene.delegate = self;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
}
感谢您的帮助!所以尝试,我得到一个错误行self = [超级initWithNibName:0 = nibNameOrNil捆绑:nibBundleOrNil]; 表达式不可分配。另一个表示预期表达式的其他人说,NSDate * newDate2 = [gregorian dateByAddingComponents:components toDate:now options:0];表示不兼容的指针类型。这是因为NSDate格式化程序现在被声明了两次? – 2014-09-05 21:07:33
@ user3856938我编辑了帖子......!还有[super initWith ..]被调用的地方。这种变化与他们没有任何关系! – nikhil84 2014-09-08 05:28:20