當我在我的應用程序中去看看控制器時,我有兩個日期選擇器。兩者都有標籤,如果任何一個被移動,他們會相應地更新。用戶界面日期選擇器不顯示在標籤
開始日期被設置爲自動成爲今天的日期。雖然它保存到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