Welcome, Guest
Username Password: Remember me

SCSelectionAttributes attributesWithDictionary:
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: SCSelectionAttributes attributesWithDictionary:

SCSelectionAttributes attributesWithDictionary: 1 year, 3 months ago #1

I need a mechanism to create a SCSelectionAttributes using a dictionary that maps from display values to actual property values and back, so that for example a property value of @"1" is rendered as @"Bug". This would be nice to have in SCSegmentedAttributes as well. I am trying to hook up a STVC to an array of SOAP objects (RemoteIssue generated by sudzc from the Jira WSDL) and I have no control over the datatype of the properties and I need to map some of these properties like type, priority and status from numeric values (unfortunately stored as strings) to something human readable.

Thanks,

Frank
  • fsauer
  • OFFLINE
  • Fresh Boarder
  • Posts: 14
  • Karma: 1

Re: SCSelectionAttributes attributesWithDictionary: 1 year, 3 months ago #2

Hi Frank,

I've actually tried reading this several times, but I think I am still a bit lost Would you please explain more or give an example? Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: SCSelectionAttributes attributesWithDictionary: 1 year, 3 months ago #3

Sorry, it was late...

I have objects that have a NSString property that contains keys like @"1", @"2", @"3", etc. I am not 100% certain these are always numeric and I don't want to make that assumption. However, I also have an array of objects that have these same keys, as well as a display string that I want to use in the UI. So I thought it would be nice to have a way to give STV a map with mappings from those keys to the strings I want to use in the UI, like @"Bug", @"New Feature", @"Enhancement", etc. Something like:

 
[SCSelectionAttributes attributesWithDictionary:
[NSDictionary dictionaryWithObjectsAndKeys: @"Bug", @"1", @"New Feature", @"2", @"Enhancement", @"3", nil]
 
...]
 


Or perhaps to keep things ordered as well:

 
SCSelectionAttributes attributesWithKeys: [NSArray arrayWithObjects: @"1", @"2", @"3", nil]
values: [NSArray arrayWithObjects: @"Bug", @"New Feature", @"Enhancement", nil]
 



Hope it makes more sense now...In short a way to have a non-numeric index based mapping from property values to display values

Thanks,

Frank
  • fsauer
  • OFFLINE
  • Fresh Boarder
  • Posts: 14
  • Karma: 1

Re: SCSelectionAttributes attributesWithDictionary: 1 year, 3 months ago #4

Hi Frank,

I think the following is the best way to handle your custom situation:

1- Create a simple SCSelectionCell and add it to your section (or detail section)

 
...
SCSelectionCell *selectionCell = [SCSelectionCell cellWithText:@"Select"];
[mySection addCell:selectionCell];
...
 


2- Configure the cell at runtime by implementing willConfigureCell

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
willConfigureCell:(SCTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if([cell isKindOfClass:[SCSelectionCell class]])
{
SCSelectionCell *selectionCell = (SCSelectionCell *)cell;
selectionCell.items = [NSArray arrayWithObjects:...]; // your object titles here
selectionCell.selectedItemIndex = [NSNumber numberWithInt:...]; // index of selected object
}
}
 


3- Map the selection back as soon as the cell value changes

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
valueChangedForRowAtIndexPath:(NSIndexPath *)indexPath
{
SCTableViewCell *cell = [tableViewModel cellAtIndexPath:indexPath];
if([cell isKindOfClass:[SCSelectionCell class]])
{
SCSelectionCell *selectionCell = (SCSelectionCell *)cell;
NSInteger selectionIndex = [selectionCell.selectedItemIndex intValue];
...
// Your mapping code here
}
}
 


Hope this helps!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
Time to create page: 0.96 seconds