UA-17470720-3

Jump to content


Photo
- - - - -

Question on right selection for described scenario


  • Please log in to reply
13 replies to this topic

#1 RaduGrama

RaduGrama

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 29 posts
  • LocationTampa, FL
Reputation: 6
Good

Posted 13 May 2016 - 08:55 AM

Hi guys,

 

I have scenario where I have a simple Core Data entity that I manage via STV but one of the fields is a lookup field with standard name/value pair functionality expected. It is expected that the name is displayed in the master and edit views, but the value is stored in the actual field. In addition, the values for the lookup do not come from Core Data but are dynamically determined at runtime (they are available in viewDidLoad).

 

Any suggestions on the appropriate type for the field? I assume Selection is too simple but I'm not sure which one would work best between Object Selection and Array of Objects and also where and how to initialize the lookup data?

 

Thank you!



#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 13 May 2016 - 09:37 AM

Hi Radu,

 

Would you please share a more elaborate example of what you're trying to achieve?



#3 RaduGrama

RaduGrama

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 29 posts
  • LocationTampa, FL
Reputation: 6
Good

Posted 13 May 2016 - 03:57 PM

Hi Tarek,

 

Sure, in Core Data I have an entity that has a title, description and date. For the date, the requirement is to pick a date from the next 3 business days and those need to be calculated since they could be the next 3 calendar days or they could be split if the next 3 calendar days overlap with the weekend. The requirement is when the user clicks the date field they are taken to a screen where they can select one of those 3 calculated dates, and also the dates have specific formatting requirements while the actual data written in the entity is different (name value pair behavior, name being displayed, value being stored).

 

Please let me know if this explains the requirements.

 

Thank you!



#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 13 May 2016 - 05:39 PM

Thank you Radu, I got it now. There are many ways to do this in STV. Here are a couple of options that first came to my mind:

 

a. Add a regular SCObjectSelectionCell at runtime (e.g. sectionActions.detailModelConfigured), and setup it's 'items' property to include the dates.

 

    NSDate *firstDate, *secondDate, *thirdDate;  // Calculate dates here
    
    SCObjectSelectionCell *dateSelectionCell = [SCObjectSelectionCell cellWithText:@"Select Date" boundObject:myObject selectedObjectPropertyName:@"datePropertyName" selectionItems:@[firstDate, secondDate, thirdDate] itemsDefintion:[SCDateDefinition definition]];
    [mySection addCell:dateSelectionCell];

 

b. If you don't like adding stuff at runtime, another option would be to subclass SCDateSelectionCell (pretty much like above), and add it as a custom property definition in IB.

 

Hope this helps.



#5 RaduGrama

RaduGrama

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 29 posts
  • LocationTampa, FL
Reputation: 6
Good

Posted 14 May 2016 - 05:35 AM

Hi Tarek,

 

On option a), not sure I follow how I configure the actual strings/labels/captions to display (which need to be different than the values to actually store in the bound object). You also refer to definition, where is that coming from (parameter or it needs to be retrieved somehow)? Also, I am not sure I understand what am I supposed to do with the property in the class definition, include it, not include it, set it not to display by default?

 

Thank you!


Edited by RaduGrama, 14 May 2016 - 05:38 AM.


#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 14 May 2016 - 06:26 AM

Hi Radu,

 

1. You can always set the cellActions.willDisplay and set whatever value you want to SCObjectSelectionCell.label

 

2. Since you'll be adding the cell at runtime in option (a), you should not include any property definition at all for the date selection in IB.

 

Please let me know if you still need more help.



#7 RaduGrama

RaduGrama

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 29 posts
  • LocationTampa, FL
Reputation: 6
Good

Posted 14 May 2016 - 08:35 AM

Tarek,

 

Any other option on this, I would assume this is a fairly common scenario and one of the various selection options would handle it.  For SCObjectSelectionCell it's not very clear how to initialize it and where all the parameter values should come from.

 

Thank you! 



#8 RaduGrama

RaduGrama

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 29 posts
  • LocationTampa, FL
Reputation: 6
Good

Posted 14 May 2016 - 09:05 AM

Tarek,

 

I tried a) and the cell does not display at all (no errors), but I am not sure about the correct values for the following parameters:

- boundObject - I'm assuming that will be section.boundObject

selectionItems - What type should they be, what type should they match (the one of the data type in the entity)?

itemsDefintion - Where does this come from, any dataDefinitionWithIBName call will not return them since they definition for that field does not need to be included in the data definition, so this would need to be constructed manually and if so how?

 

Thank you!



#9 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 14 May 2016 - 09:10 AM

Hi Radu,

 

- boundObject is indeed section.boundObject

- The selectionItems are NSDate objects, and the data definition is a ready made definition for NSDate, called SCDateDefinition (please refer to my code above). 

 

I am really not sure why the cell isn't appearing. Would you please post your code?



#10 RaduGrama

RaduGrama

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 29 posts
  • LocationTampa, FL
Reputation: 6
Good

Posted 14 May 2016 - 09:15 AM

Code included below, please keep in mind I'm using strings not dates, dates just made it easy to give an example:

 

 

        self.tableViewModel.sectionActions.detailModelConfigured = {
            (section, detailModel, indexPath) in
            let jPCell = SCObjectSelectionCell(text: "JP", boundObject: section.boundObject, selectedObjectPropertyName: "jPData", selectionItems: ["A", "B"], itemsDefintion: SCDataDefinition())
            section.addCell(jPCell)
        }

 

Thank you!



#11 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 14 May 2016 - 09:37 AM

Thanks for the code. Here are the problems I could see:

 

a. Please note that 'section' isn't the section you're trying to add the cell to, but is rather your main master section. The section you're trying to add the cell to is the detail section, which can be accessed via 'detailModel'.

 

b. Since your data type is NSString, you should be either using a regular SCSelectionCell, or keep the same code and use SCStringDefinition for the data definition.

 

Here is how your updated code should look like:

self.tableViewModel.sectionActions.detailModelConfigured = {
            (section, detailModel, indexPath) in
            let detailSection = detailModel.sectionAtIndex(0)
            let jPCell = SCObjectSelectionCell(text: "JP", boundObject: detailSection.boundObject, selectedObjectPropertyName: "jPData", selectionItems: ["A", "B"], itemsDefintion: SCStringDefinition())
            detailSection.addCell(jPCell)
}

 

Hope this helps.



#12 RaduGrama

RaduGrama

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 29 posts
  • LocationTampa, FL
Reputation: 6
Good

Posted 14 May 2016 - 09:48 AM

Hi Tarek,

 

Thank you! That works for the selection, one issue is that once I select "A" or "B", in the detail view I can see the "JP" label but the selected values ("A" or "B") do not show up.

 

Thank you!



#13 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 14 May 2016 - 10:02 AM

You're welcome Radu. I am really not sure what you mean, but would you please try just using a regular SCSelectionCell instead and see if it achieves your desired result?

 

let jPCell = SCSelectionCell(text: "JP", boundObject: detailSection.boundObject, selectionStringPropertyName: "jPData", items: ["A", "B"])

 

By default, the above code will store the selected string into the property called "jPData". If you want to store something else there, then you could implement cellActions.valueChanged and set whatever you want there based on the cell's 'selectedItemIndex' property.


Edited by Tarek, 14 May 2016 - 10:03 AM.
Fixed a typo


#14 RaduGrama

RaduGrama

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 29 posts
  • LocationTampa, FL
Reputation: 6
Good

Posted 14 May 2016 - 08:46 PM

Hi Tarek,

 

That worked! In the end I used cellActions.valueChanged and set a different field to a value determined based on whatever was selected in jPData.

 

Thanks again!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users