UA-17470720-3

Jump to content


Photo
- - - - -

SCObjectSelectionCell preselected option


  • Please log in to reply
10 replies to this topic

#1 sebaro1989

sebaro1989

    Jr. Member

  • STV Lite
  • PipPip
  • 17 posts
Reputation: 4
Good

Posted 09 September 2015 - 08:33 AM

Hi, i´m currently showing a list of options for an entity, in case there is only one option I want it to be preselected to avoid making the user to drill in:

 

 

 

SCObjectSelectionCell *carsCell = [SCObjectSelectionCell cellWithText:@"Cars"

                                                                  boundObject:self.fieldFilter

                                                   selectedObjectPropertyName:@"selectedCars"

                                                          selectionItemsStore:[self buildCarStore]];

 

//First I should check if there is only one car.

[carsCell setSelectedItemIndex:0];

 

I tried with this setSelected method but the app crashes, is there any way to set one object for the selection cell?

 

 

Thanks!!

 



#2 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 09 September 2015 - 10:07 PM

Hi sebaro1989,

 

The selectedItemIndex needs to be a NSNumber so this should work:

 

[carsCell setSelectedItemIndex:[NSNumber numberWithInt:0]];

  • Tarek likes this
Cheers,

Dave

www.dgapps.ie

#3 sebaro1989

sebaro1989

    Jr. Member

  • STV Lite
  • PipPip
  • 17 posts
Reputation: 4
Good

Posted 10 September 2015 - 06:31 AM

Hi Dave, thanks for your quick reply!

After this comment I realise i was making a mistake and I change it, but the original cell and the selection view are not getting updated. They are not showing the information about the selected item and when I drill in this object is not selected. Is there any other way to modify this behaviour?

Thanks!

Edited by sebaro1989, 10 September 2015 - 06:32 AM.


#4 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 10 September 2015 - 07:57 AM

Hi sebaro1989,

 

 

Where are you setting your selectedItemIndex? In the carsCell.cellAction.didConfigure block should do it I think.


  • Tarek likes this
Cheers,

Dave

www.dgapps.ie

#5 sebaro1989

sebaro1989

    Jr. Member

  • STV Lite
  • PipPip
  • 17 posts
Reputation: 4
Good

Posted 11 September 2015 - 01:00 PM

That was the problem, I ended up adding it to:

 

carsCell.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {

        

            [carsCell setSelectedItemIndex:[NSNumber numberWithInt:0]];

        };

 

And it worked!

Thanks!


  • Tarek likes this

#6 sebaro1989

sebaro1989

    Jr. Member

  • STV Lite
  • PipPip
  • 17 posts
Reputation: 4
Good

Posted 20 November 2015 - 10:53 AM

Hi, since I upgraded my STV version to the last one this has stopped working, is there anything that I should change?

 

 

Thanks!!



#7 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 20 November 2015 - 11:08 AM

Hi sebaro1989,

 

That code should still work in STV 5.1.3.

 

Is the willConfigure block getting called?


Cheers,

Dave

www.dgapps.ie

#8 sebaro1989

sebaro1989

    Jr. Member

  • STV Lite
  • PipPip
  • 17 posts
Reputation: 4
Good

Posted 20 November 2015 - 11:55 AM

Hi Dave,

 

Yes, the block is getting called, and if I drill into the list the option is selected.

But the cell is not showing the selected cell information (Unless i drill into de options list and press Done), is there any way to force the cell to update its UI so it displays the current boundObject?

 

Thanks!



#9 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 21 November 2015 - 05:41 AM

Hi sebaro1989,

 

I've looked back at the code you gave and your said this was your willConfigure:

 

carsCell.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
        
            [carsCell setSelectedItemIndex:[NSNumber numberWithInt:0]];
        };

 

 

 

If you set the selectedItemIndex on the cell, and not on the carsCell:

 

 

[cell setSelectedItemIndex:[NSNumber numberWithInt:0]];

 

 

does that fix your issue?

 

 

If not, then does calling a reloadBoundValue help, so your full willConfigure would be:

 

 

carsCell.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
            [cell setSelectedItemIndex:[NSNumber numberWithInt:0]];
            [cell reloadBoundValue];
        };

 

I had issues with SCObjectSelectionCell and dynamic predicates, and calling the reloadBoundValue there sorted that out:

 

http://sensiblecocoa...cell#entry10549

 


Cheers,

Dave

www.dgapps.ie

#10 sebaro1989

sebaro1989

    Jr. Member

  • STV Lite
  • PipPip
  • 17 posts
Reputation: 4
Good

Posted 23 November 2015 - 05:29 AM

Hi Dave, 

 

I have tried it out but SCTableViewCell does not have a SetSelectedItemIndex, so I casted it to SCObjectSelectionCell, and it didn´t work. Maybe I´m not understanding it correctly but shouldn´t I select the index from the origina SCObjectSelectionCell? This was the way it was done before upgrading and it was working, also if I reloadBoundValues it doesn't even get previously selected when I drill in.

 

 

SCObjectSelectionCell *retailerCell = [SCObjectSelectionCell cellWithText:@"Retailers"
                                                         boundObject:self.fieldFilter
                                             selectedObjectPropertyName:@"selectedRetailers"
                                             selectionItemsStore:[self buildRetailerStore]];

retailerCell.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) { 

SCObjectSelectionCell *objectSelectionCell = (SCObjectSelectionCell *)cell; 

[objectSelectionCell setSelectedItemIndex:[NSNumber numberWithInt:0]]; 
[objectSelectionCell reloadBoundValue]; 

};

 

 

Do you have any other idea?

 

Thanks for taking the time to help me,

Cheers,

Sebastián Vázquez


Edited by sebaro1989, 23 November 2015 - 05:32 AM.


#11 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 23 November 2015 - 08:13 PM

Greetings Programs!

 

I added this to the CoreData sample app and it worked very well.

 

SCEntityDefinition *task = (SCEntityDefinition *)[self dataDefinitionWithIBName:@"TaskEntity"];
SCPropertyDefinition *category = (SCPropertyDefinition *)[task propertyDefinitionWithName:@"category"];

category.cellActions.didLoadBoundValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath, NSObject *value)
{
	SCSelectionCell *selectionCell = (SCSelectionCell *)cell;

	if (selectionCell.items.count == 1) {
		selectionCell.selectedItemIndex = [NSNumber numberWithInteger:0];
                value = [selectionCell.items objectAtIndex:0];
	}
	
	return value;
};

 

Also, if you use willConfigure, the value is selected but you will need to set the label of the SCSelectionCell to the selected value:

 

category.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
{
    SCSelectionCell *selectionCell = (SCSelectionCell *)cell;
    
    if (selectionCell.items.count != 1) { return; }
    
    [selectionCell setSelectedItemIndex:[NSNumber numberWithInt:0]];
    selectionCell.label.text = [selectionCell.items objectAtIndex:0];
};

 

And reloadBoundValue won't work because it will reload the current value of the property in core data and not the currently selected value.

 

Wg


Edited by wizgod, 24 November 2015 - 09:59 AM.

  • Tarek likes this

P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users