objective c - UIDatePicker.date bug -
i'm having problem getting date uidatepicker. know code of getting date, keeps on getting current date, not date form picker.
- (ibaction)buttonpressed:(uibutton *)sender { nsdateformatter *formate = [[nsdateformatter alloc]init]; nsdate *setteddate = self.mypickeddate.date; [formate setdateformat: @"dd.mmm.yyyy @ hh:mm:ss"]; nsstring *datestring = [formate stringfromdate:setteddate]; nslog(@"datestring: %@", datestring); }
i set mypicker 15th may 2015 15:30 , xcode logs out current date (if it's 16:19 log out 22nd.apr.2015 16:19, no matter what.
xcode 5.1.1 on simulator ios 7.1.2 (haven't tried on real device).
the problem in viewdidload
saying this:
self.mypickeddate = [[uidatepicker alloc] init];
so, think code. doing there creating new date picker, different 1 in interface, , substituting 1 in interface, self.mypickeddate
set (because outlet). on, self.mypickeddate
refers different date picker, 1 not in interface (it merely held in memory)! therefore, nothing in interface, such setting date in date picker see there, has effect on self.mypickeddate
.
therefore, solve problem, delete line of code.
Comments
Post a Comment