UA-17470720-3

Jump to content


Photo
- - - - -

How to get NSDate date with date picker?

cells

  • Please log in to reply
5 replies to this topic

#1 fabiensen

fabiensen

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 5
Good

Posted 17 April 2015 - 11:22 AM

Hi all

 

when adding a date type attribute, I get a UIDatePickerView in a cell. But how to select the current date/time (which I see by default)?

 

I have to choose a date in the past or in the future and go back to the current one to have it saved.

 

Do you have a solution for that?

 

Regards

Fabio


  • Adjuramum likes this

#2 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 17 April 2015 - 10:21 PM

Greetings Program!

In willDisplay or willConfigure, I check to see if the boundObject date is already set and if not, I set it to my default date and let STV take care of the rest.

Wg
  • Tarek likes this

P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#3 fabiensen

fabiensen

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 5
Good

Posted 18 April 2015 - 06:31 AM

Hi,

 

thank to your suggestion I did like that:

 

- subclassed the SCTableViewController

- in its viewDidLoad I have what is pasted below (it is working ;)

 

Thank you very much, hope that it can help someone!

 

self.tableViewModel.cellActions.willDisplay =  ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
        
        if  ([cell isKindOfClass:[SCDateCell class]]) {
            
            if (!cell.boundValue.description) {
                [cell setBoundValue:[NSDate date]];
                [cell reloadBoundValue];
            }
 
        }
            
    };


  • Tarek likes this

#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 20 April 2015 - 04:47 AM

There is also an additional way: STV lets you precisely control the values it reads/writes from/to your objects' properties using cellActions.didLoadBoundValue / cellActions.willCommitBoundValue.

 

self.tableViewModel.cellActions.didLoadBoundValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath, NSObject *value) {

        if  ([cell isKindOfClass:[SCDateCell class]]) {          
            if (!value) {
                return [NSDate date];
            } 
        }
         
        return value;   
    };

 

It's really a matter of taste which way to use, but I find the above to be the most clear and elegant, plus it's slightly more efficient since you don't need to issue '[cell reloadBoundValue'.


  • ozie and wizgod like this

#5 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 20 April 2015 - 10:12 PM

see i learn something new every day reading the forums


  • Tarek likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#6 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 27 March 2016 - 03:39 AM

I had to alter Tareks code above just a little.. as it seems that this sets the date picker date, but when I tap done this date value is not entered into the core data object

 

this worked for me

self.tableViewModel.cellActions.didLoadBoundValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath, NSObject *value) {
        
        if  ([cell isKindOfClass:[SCDateCell class]]) {
            if (!value) {
                
                NSDate *d = [NSDate date];
                [cell.boundObject setValue:d forKey:@"timeStamp"];
                return d;
            }
        }
        
        return value;
    };

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.






Also tagged with one or more of these keywords: cells

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users