UA-17470720-3

Jump to content


Photo
- - - - -

Format


  • Please log in to reply
2 replies to this topic

#1 designwerks

designwerks

    Advanced Member

  • STV 5.0 Std
  • PipPipPipPipPip
  • 139 posts
  • LocationKingsville, Ontario, Canada
Reputation: 23
Excellent

Posted 19 March 2018 - 04:52 PM

I have a NSNumber from core data that needs to have a % sign after the number displayed... The problem is the number comes from core data and is displayed using the code from a nib... I have no way to format that display... it simply comes from this 9:subtotal

 

{
            SCCustomCell *customCell = [SCCustomCell cellWithText:nil

                                             objectBindingsString:@"1:plantName.title;2:plantCondition.title;3:plantSize.title;4:price;11:dateofHire;9:subtotal;10:subtotal_additional_costs;"
                                                          nibName:@"plantCell2"];

 

I notice in the debugger panel that the NSNumber is converted to an NSString and the % sign is appended to the end. BUT it does not show up that way in my tableviewcell from the above code (again - as I use the custom cell calling tag #9 in plantCell2... any ideas? Images attached for review...

 

- (void)calculateAdditionalCosts {
    
    NSString *keyadditionalcosts = @"subtotal_additional_costs";
    
    float vacationvalue =         [self.vacationpay floatValue];
    float unemploymentvalue =     [self.unemployment floatValue];
    float socialsecurityvalue =   [self.socialsecuritytax floatValue];
    float medicarevalue =         [self.medicaretax floatValue];
    float commissonvalue =        [self.commissionrate floatValue];
    float allowancevalue =        [self.allowancerate floatValue];
    float othervalue =            [self.othertax floatValue];
    
    float sstotal_additionalcosts = ((vacationvalue) +
                                    (unemploymentvalue) +
                                    (socialsecurityvalue) +
                                    (medicarevalue) +
                                    (commissonvalue) +
                                    (allowancevalue) +
                                    (othervalue)); // convert to show %
    
    [self willChangeValueForKey:keyadditionalcosts];
    
    self.subtotal_additional_costs = [NSNumber numberWithFloat:sstotal_additionalcosts];
    
    NSString *myString = [NSString stringWithFormat:@"%@", [NSNumber numberWithFloat:sstotal_additionalcosts]];
    myString = [myString stringByAppendingString:@"%"];
    NSLog(@"%@", myString);
    
}

The number is displayed correctly mathematically... just wish I could format that number result to show the % symbol and also, the $ on one of my other numbers...

 

 

 

 

Attached Files



#2 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 20 March 2018 - 01:36 AM

might be done in cell "willDisplay"

 

self.tableViewModel.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
{
if([cell isKindOfClass:[SCCustomCell class]])
{
NSDate *duration = [cell.boundObject valueForKey:@"duration"];
//format the date eg. remove 0000
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSString *newDateString = [dateFormatter stringFromDate:duration];

UILabel *dateLabel = (UILabel *)[cell viewWithTag:2];
dateLabel.text = newDateString;
}
};

 

but instead of date.. use your code:)


  • Dave Guerin and designwerks like this

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


#3 designwerks

designwerks

    Advanced Member

  • STV 5.0 Std
  • PipPipPipPipPip
  • 139 posts
  • LocationKingsville, Ontario, Canada
Reputation: 23
Excellent

Posted 20 March 2018 - 05:17 AM

might be done in cell "willDisplay"

 

self.tableViewModel.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
{
if([cell isKindOfClass:[SCCustomCell class]])
{
NSDate *duration = [cell.boundObject valueForKey:@"duration"];
//format the date eg. remove 0000
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSString *newDateString = [dateFormatter stringFromDate:duration];

UILabel *dateLabel = (UILabel *)[cell viewWithTag:2];
dateLabel.text = newDateString;
}
};

 

but instead of date.. use your code:)

 

You are the man!... Your code works... I was always struggling with how to reference (to format) the objectBindingsSting to format as text when I did not know how to call out the .text... looking at your code it all makes sense... thanks for your help...!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users