Sunday, 15 June 2014

ios - set uidatepicker date from string -


Question: Renewed question:

I have an application where the user can add a new workshop along with a workshop date. After that, he chooses from a UIDatePicker After this, the user can edit the workshop information including editing. The following is what I am trying to do: 1. When the user adds a new workshop, read the time to select the user from UIDatePicker . 2. Convert date to string and save it to database. 3. When the user wants to edit the workshop, I should get the workshop date from the database and change it from string to NSDate . 4. UIDatePicker is built in "interface" in NSDate .

I think this sound is logical. However, this is not working for me and I'm not sure why the code is here:

In the AddWorkshop.m class

  NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init]; [DateFormat setDateStyle: NSDateFormatterMediumStyle]; // WSDate a NSString variable self.WSDate = [dateFormat stringFromDate: [sender date]];  

In the EditWorkshop.m category

  NSDateFormatter * df = [[NSDateFormatter alloc] init]; [DF Settte Stella: NSDAT Formamium Style]; NSDate * date1 = [df dateFromString: self.WSDate]; [Self-portrait picture set date: date 1];  

The problem is:

  1. UIDatePicker will not change the date The specified date, It always shows on today's date.

  2. When I have the NSLOG date 1 and myself If I try WDDate, the value of date 1 is always one day low then self.WSDate

  3. [UIDTPK set date: NSDT] has a specific format for the date passed? For example: Is it ok to have "MMMM DD Yay" or "MMD-DD-YEY" or any format?

Advertisement 1: from visibleDidoad You want to update your code, it is called only once your view loads. So it can be an issue in your case. Try calling the ad from viewWillAppear: or viewDidAppear:

Ad 2: This is probably a timezone problem NSDate And NSString .

Ad 3: Try to process date instead of changing back and backward between NSDate > Date set: one NSDate < / Code> is expected, in which there is no format, think something like an integer.


No comments:

Post a Comment