UA-17470720-3

Jump to content


Photo
- - - - -

User Defaults Definition - Store index of selected detail item


  • Please log in to reply
8 replies to this topic

#1 Sam Gerardi

Sam Gerardi

    Jr. Member

  • STV 3.0 Std
  • PipPip
  • 27 posts
  • LocationSan Diego, CA
Reputation: 5
Good

Posted 14 April 2013 - 09:47 PM

I am using the SCUserDefaultsDefinition to create a settings menu. Some of the cells in are Selection type cells that present a list of items to the user. Example: Default View > Grid View, List View. When a selection is made, the value stored in the plist is the value of the string the user selected (Grid View or List View).

Is there a way to store the index of the item selected, rather than the value of the cell text?

Thank you!

#2 Sam Gerardi

Sam Gerardi

    Jr. Member

  • STV 3.0 Std
  • PipPip
  • 27 posts
  • LocationSan Diego, CA
Reputation: 5
Good

Posted 14 April 2013 - 10:09 PM

I think I answered my own question...

if ( cell type is an SCSelection Cell ) {
NSUInteger selectedIndex = [detailModel.activeCellIndexPath row];
[[NSUserDefaults standardUserDefaults] setInteger:selectedIndex forKey:cell.boundPropertyName];
}


#3 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 16 April 2013 - 08:15 PM

Please let me know if you still need help.

#4 skrew

skrew

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 21 posts
Reputation: 3
Good

Posted 12 August 2015 - 04:31 PM

Hi,

 

I'm new to STV and i need help, so instead of creating a new topic, i make a reply here.

 

I have the same situation and my settings part are IB only. I think there are nothing to do without making code, right ?

 

 

Thanks.



#5 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 12 August 2015 - 06:42 PM

Hi skrew,

 

Yes, it's basically done through code. Sam showed one example above, and I'll give you another one. To have our bundled UserDefaultsApp sample store ringtone as an index, you'd add the following code to MasterViewController.m:

 

@implementation MasterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    SCObjectSection *alarmSection = (SCObjectSection *)[self.tableViewModel sectionAtIndex:1];
    SCSelectionCell *ringtoneSelectionCell = (SCSelectionCell *)[alarmSection cellForPropertyName:@"ringtone"];
    ringtoneSelectionCell.boundPropertyDataType = SCDataTypeInt;
}

@end

 

Please let me know if you need any further help with this.



#6 skrew

skrew

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 21 posts
Reputation: 3
Good

Posted 13 August 2015 - 07:58 AM

Hi Tarek,

 

Edit: I just tested with your example in UserDefaultApp, and it don't works:

When i look in prefs, i see 'ringtone = "Ring B"'


It still save string instead of indexes.

Maybe my configuration in IB?


s2FiCbr.png


Edited by skrew, 13 August 2015 - 08:11 AM.


#7 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 13 August 2015 - 08:33 AM

Hi skrew,

 

Yes, I just tested it and it's not working, which seems to be an STV bug. I really apologize for not testing the code before posting. Please use the following code instead:

 

@implementation MasterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    SCObjectSection *alarmSection = (SCObjectSection *)[self.tableViewModel sectionAtIndex:1];
    SCSelectionCell *ringtoneSelectionCell = (SCSelectionCell *)[alarmSection cellForPropertyName:@"ringtone"];
    ringtoneSelectionCell.cellActions.willCommitBoundValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath, NSObject *value)
    {
        return [(SCSelectionCell *)cell selectedItemIndex];
    };
}

@end

 

 

Also, based on your input, we're now working on having this feature accessible right from IB without you having to do any coding. Please let me know if you need any further help.


Edited by Tarek, 13 August 2015 - 08:35 AM.
Fix


#8 skrew

skrew

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 21 posts
Reputation: 3
Good

Posted 13 August 2015 - 09:16 AM

Ok thanks Tarek, it's works now.

And having this feature in IB are a good news too ;)


  • Tarek likes this

#9 skrew

skrew

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 21 posts
Reputation: 3
Good

Posted 21 January 2016 - 10:23 AM

Hi,

 

Any news about storing indexes without using code ?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users