UA-17470720-3

Jump to content


Photo
- - - - -

SCSelectionAttributes attributesWithDictionary:


  • Please log in to reply
4 replies to this topic

#1 Frank Sauer

Frank Sauer

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 0
Neutral

Posted 23 January 2011 - 09:09 PM

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

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 24 January 2011 - 09:31 AM

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!

#3 Frank Sauer

Frank Sauer

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 0
Neutral

Posted 24 January 2011 - 09:41 AM

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

#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 24 January 2011 - 10:44 AM

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! :)

#5 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 02 May 2013 - 02:37 AM

i just tried this.. but selectionCell.items.. items is readonly

 

 

**edit**

fixed in 3.2.1 from readonly  :)


Edited by ozie, 30 May 2013 - 01:26 AM.

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users