UA-17470720-3

Jump to content


Photo
- - - - -

action to compute field value

actions

  • Please log in to reply
6 replies to this topic

#1 gayraud

gayraud

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 28 posts
Reputation: 0
Neutral

Posted 02 December 2015 - 12:13 AM

I was in the process of migrating STV 3.x to STV 5.x. So for that I moved all my delegates methods to actions.

Everything went smooth, thanks to Tarek ;-)

But I still have a last issue on "updating a field". I need to process a numerical value (convert to a specific unit depending on user preferences) before displaying it on the cell.

 

With STV3.x it was working great. On STV5.x I put my 5 lines of code inside the corresponding action, the processing of the "new value" is working ok, but the display is not updating accordingly (user still see the current value - without the unit conversion).

 

Someone has a clue ?

 

 

    // detailViewWillPresentForRowAtIndexPath

    measuresSection.sectionActions.detailModelWillPresent = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)

    {

        SCTableViewCell *myCell = [self.tableViewModel cellAtIndexPath:indexPath];

        Measure *myObject = (Measure *)myCell.boundObject;        

        double current_val=[myObject.value doubleValue];

        double new_val=... // do the processing        

        myObject.value=[NSNumber numberWithDouble:new_val];

    };



#2 wizgod

wizgod

    I'm what you guys call a User

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

Posted 02 December 2015 - 06:10 AM

Greetings Program!


Try putting it in the didLoadBoundValue action:

 

measuresSection.sectionActions.detailModelConfigured = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
{
	detailModel.cellActions.didLoadBoundValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath, NSObject *value)
	{
		Measure *myObject = (Measure *)cell.boundObject;
		double current_val = [(NSString *)value doubleValue];
		double new_val = current_val; // do the processing
		
		return [NSNumber numberWithDouble:new_val];
	};
};

 

Wg


  • Tarek likes this

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


#3 gayraud

gayraud

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 28 posts
Reputation: 0
Neutral

Posted 02 December 2015 - 09:46 AM

Thanks

I finally changed a little your code to the foliowing. It's working good when the detail view is displayed. But unfortunately the processing is running when I am trying update the value of this field (named "value").

I need to fire the conversion processing only when the detail view is displayed (like -viewWillAppear in a view controller).

Any suggestion ?

 

 

    measuresSection.sectionActions.detailModelConfigured = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)

    {

        if (indexPath.row==NSNotFound)

            return;

        

        detailModel.cellActions.didLoadBoundValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath, NSObject *value)

        {

            if ([cell.boundPropertyName isEqualToString:@"value"]) {

                double val = [(NSString *)value doubleValue];

                double new_val=val; // processing                

                return [NSNumber numberWithDouble:new_val];

            }

            return value;

        };

    };

 

 

I noticed that the problem is related to the other part of my code which verifying value upon limits

    

valuePropDef.cellActions.valueIsValid = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath)

    {

        BOOL valid=NO;

        SCNumericTextFieldCell *tmp = (SCNumericTextFieldCell *)cell;

        NSString *valStr=tmp.textField.text;

        float value_unit=[valPoint floatValue];

        if(val>=VERYMIN_UNIT1 && val<=VERYMAX_UNIT1) valid=YES;

        return valid;

    };

 

How can I used at the same time .valueIsValid in order to check limit in real time, and also use .didLoadBoundValue to update display only the first time the detail view is displayed ?


Edited by gayraud, 02 December 2015 - 10:43 AM.


#4 wizgod

wizgod

    I'm what you guys call a User

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

Posted 02 December 2015 - 10:30 AM

Use the willDisplay cell action instead and set the control's label text to the calculated value.

 

Wg


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


#5 gayraud

gayraud

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 28 posts
Reputation: 0
Neutral

Posted 02 December 2015 - 11:09 AM

Following your proposal I added the following code, but this time, I don't understand why, the .willDisplay is fired 2 times, so my value is converted 2 times (so the result is wrong).

Any help ?

 

    valuePropDef.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath)

    {

        SCNumericTextFieldCell *tmp = (SCNumericTextFieldCell *)cell;

        tmp.textField.textAlignment = NSTextAlignmentRight;

        tmp.textField.keyboardType = UIKeyboardTypeDecimalPad;

        NSString *valStr=tmp.textField.text;

        double val = [valStr doubleValue];

        double new_val=val; // processing

        tmp.textField.text=[NSString stringWithFormat:@"%f",new_val];

    };



#6 wizgod

wizgod

    I'm what you guys call a User

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

Posted 02 December 2015 - 11:34 AM

It's because you're taking the value from the text field; you should use the boundValue.

 

Replace:

 

NSString *valStr=tmp.textField.text;
double val = [valStr doubleValue];

With:

 

double val = [(NSString *)cell.boundValue doubleValue];

 

Wg


  • Tarek likes this

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


#7 gayraud

gayraud

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 28 posts
Reputation: 0
Neutral

Posted 02 December 2015 - 11:41 AM

Great !

That was really tricky, I would have never found that myself ;-)

Many thanks Wizgod, problem fixed !







Also tagged with one or more of these keywords: actions

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users