Welcome, Guest
Username Password: Remember me

UIDatePickerModeDate
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: UIDatePickerModeDate

UIDatePickerModeDate 1 year, 4 months ago #1

Hi,

First I'd like to thank Tarek for his great help thru email on guiding me thru leveraging STV on one part of my app!
Outstanding customer service!

I'm wondering if there's a way to override the default STV datePickerMode for a date picker?
I'd like to have a UIDatePickerModeDate, instead of the one out of the box.

I saw a few other posts that were in the vicinity of this, but it was a bit in context of something else.

Thanks!
  • chinjazz
  • OFFLINE
  • Senior Boarder
  • Posts: 48
  • Karma: 2

Re: UIDatePickerModeDate 1 year, 4 months ago #2

You're welcome Adam, it's always my pleasure

Regarding your question, SCDateCell fully exposes its picker via the "datePicker" property, which you can use to fully customize the picker (including the datePickerMode). Here is a code sample on how to customize the datePickerMode of an SCDateCell that is automatically generated by a class definition:

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
willConfigureCell:(SCTableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if([cell isKindOfClass:[SCDateCell class]])
{
SCDateCell *dateCell = (SCDateCell *)cell;
dateCell.datePicker.datePickerMode = UIDatePickerModeDate;
}
}
 


Hope this helps!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: UIDatePickerModeDate 1 year, 4 months ago #3

This did work like a charm!

FYI, for anyone else interested in this thread...after the SCClassDefinition the need for setting the class.uiElementDelegate = self; And of course in the header: <SCTableViewModelDataSource, SCTableViewModelDelegate, SCTableViewCellDelegate>

In the implementation file, adding a willConfigureCell and method:

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel willConfigureCell:(SCTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if([cell isKindOfClass:[SCDateCell class]])
{
SCDateCell *dateCell = (SCDateCell *)cell;
dateCell.datePicker.datePickerMode = UIDatePickerModeDate;
}
 
}
- (void)willConfigureCell:(SCTableViewCell *)cell
{
if([cell isKindOfClass:[SCDateCell class]])
{
SCDateCell *dateCell = (SCDateCell *)cell;
dateCell.datePicker.datePickerMode = UIDatePickerModeDate;
}
}
 
 


Happy Holidays!
  • chinjazz
  • OFFLINE
  • Senior Boarder
  • Posts: 48
  • Karma: 2
Last Edit: 1 year, 4 months ago by chinjazz.

Re: UIDatePickerModeDate 1 year, 4 months ago #4

Hi Adam,

You actually need to use only one of these methods, not both. Let me explain this in more detail.

For your convenience, Sensible TableView has two parallel delegate systems for you to work with, with a lot of common shared methods. One delegate system (protocol) is for the model itself (SCTableViewModelDelegate), while the other is for the model's cells (SCTableViewCellDelegate). While SCTableViewModelDelegate is sufficient to cover all your needs, sometimes the cell you want to customize is barried deep within the automatically generated detail views, and setting up its model to receive your delegate method may be a bit challenging. Here is where the class definition's uiElementDelegate comes to the rescue, allowing you to set the delegate property of individual cells.

So to be more specific, you basically have two choices when it comes to cell customization:

1- Set the model's delegate property to "self" (which is done for you automatically as soon as the model is created) and use one or more of the SCTableViewModelDelegate methods. This is mostly used for cells that belong to the root model. This method can also be perfectly used for detail models, provided that you assign the detail models' delegate property to "self". The challenge then would be for you to know which model is actually calling your delegate method. Most of our customers solve this by assigning a tag to each model as soon as it's created. Here is a code sample that illustrates what I mean:

 
// All these methods belong to the SCTableViewModelDelegate protocol
 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
detailViewWillAppearForRowAtIndexPath:(NSIndexPath *)indexPath
withDetailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
// Set a tag to uniquely identify the detail model. What I am doing here is setting
// a tag that is equivalent to the model's level in the hierarchy.
detailTableViewModel.tag = tableViewModel.tag + 1;
 
// Make sure to set the delegate property of the detail model, otherwise it won't
// be calling any of your delegate methods
detailTableViewModel.delegate = self;
}
 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
willConfigureCell:(SCTableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (tableViewModel.tag)
{
case 0: // root model
// customizations relevant to root model
break;
 
case 1: // detail model at level 1
// customizations relevant to detail model at level 1
break;
 
// etc.
}
}
 


2- Set the individual cell's delegate to "self". This saves you from worrying about which model does the cell belong to (like I did in the code sample), and will have the cell directly call its delegate method. If your cells are automatically generated via a class definition, the class definition will do two thing:
a. Each cell's tag with be set to its index within the class definition.
b. If you set the class definition's uiElementDelegate, each cell will automatically have its delegate property assigned to the value of uiElementDelegate.

With this setup, you are able to use SCTableViewCellDelegate methods like this:

 
- (void)willConfigureCell:(SCTableViewCell *)cell
{
// customize the individual cell here
}
 


Please tell me if this needs more explanation
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: UIDatePickerModeDate 1 year, 4 months ago #5

Hi Tarek,

Thanks for the expanded explanation. This does make sense to me. I hadn't realized there were 2 parallel delegate systems, and keeping track of the different models for ultimate customization with a switch on tags thru the navigable hierarchy will be very convenient, and looks to afford the most flexibility. For folks who only needed to store and capture one kind of date with picker UIDatePickerModeDate, it seems like option 2 would suffice. That being said, for future expansion of an app, it could be cause for more work later on, and option 1 may be considered a best practice.

Thanks,
Adam
  • chinjazz
  • OFFLINE
  • Senior Boarder
  • Posts: 48
  • Karma: 2

Re: UIDatePickerModeDate 1 year, 4 months ago #6

I agree with you Adam. In fact, the vast majority of our users use method no. 1 exclusively, which further proves your point. Having said that, there are some special cases where it's much more convenient to use method no. 2, so it's always a good idea to be aware of it.

Happy holidays!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
  • 2
Time to create page: 1.18 seconds