Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6015569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:51:16+00:00 2026-05-23T02:51:16+00:00

I am using the following code to display kg vs lbs in for my

  • 0

I am using the following code to display kg vs lbs in for my data in a table.

For some reason it is not working correctly and is giving me huge numbers. Any ideas?

I am using DDUnitConverter (https://github.com/davedelong/DDUnitConverter)

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
    NSString *repsText = [[managedObject valueForKey:@"reps"] description];

    NSNumber *weightInPounds = [NSNumber numberWithFloat:[[managedObject valueForKey:@"weight"]floatValue]];
    NSNumber *weightInKilos = [[DDUnitConverter massUnitConverter] convertNumber:weightInPounds fromUnit:DDMassUnitUSPounds toUnit:DDMassUnitKilograms];

    NSString *weightText = nil;
    NSString *cellText = nil;
    BOOL isKgs = [[NSUserDefaults standardUserDefaults] boolForKey:@"wantsKGs"];
    if (isKgs == 1)
    {
        weightText = [[NSString alloc]initWithFormat:@"%i", weightInKilos];
        cellText = [[NSString alloc]initWithFormat:@"Set %i: %@ reps at %@ kgs",indexPath.row + 1, repsText, weightText];
    }
    else
    {
        weightText = [[NSString alloc]initWithFormat:@"%i", weightInPounds];
        cellText = [[NSString alloc]initWithFormat:@"Set %i: %@ reps at %@ lbs",indexPath.row + 1, repsText, weightText];
    }
    cell.textLabel.text = cellText;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:51:16+00:00Added an answer on May 23, 2026 at 2:51 am

    Oh, this is an easy problem to solve. weightInKilos and weightInPounds are NSNumber instances. When you use the %i formatter in formats, it means you are supplying an integer. The integer you end up supplying is the pointer value to each object. Since you want the string value of each NSNumber, use the instance method -stringValue.

    Here’s an updated version of your code based on those changes.

    - (void) configureCell: (UITableViewCell *) cell atIndexPath: (NSIndexPath *) indexPath
    {
        NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath: indexPath];
        NSString *repsText = [[managedObject valueForKey: @"reps"] description];
    
        NSNumber *weightInPounds = [NSNumber numberWithFloat: [[managedObject valueForKey: @"weight"] floatValue]];
        // Alternatively you could just use ‘[managedObject valueForKey: @"weight"]’ if the ‘weight’ attribute is a number.
    
        NSNumber *weightInKilos = [[DDUnitConverter massUnitConverter] convertNumber: weightInPounds
                                                                            fromUnit: DDMassUnitUSPounds
                                                                              toUnit: DDMassUnitKilograms];
    
        BOOL isKgs = [[NSUserDefaults standardUserDefaults] boolForKey:@"wantsKGs"];
        NSString *weightText = (isKgs ? [weightInKilos stringValue] : [weightInPounds stringValue]);
    
        cell.textLabel.text = [NSString stringWithFormat: @"Set %i: %@ reps at %@ lbs",indexPath.row + 1, repsText, weightText];
    }
    

    Remember that you have to follow the memory management rules when dealing with objects. When you create an object using an -init... method, you have to be sure to release it. In your code that means weightText and cellText.

    PS: DDUnitConverter is a great find. I’ll have to keep it bookmarked if I ever need it in future projects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using following code to display some text and it won't change the font
I am using the following code to display a cutom 404 not found with
I am using the following code to display an index for a TableView. My
Using the following code, I am able to display up to 10 images. What
I am using the following code to try and display in a time in
I have the following code to display an image in imagebox using EmgucV: Capture
I want to display the last March month. I am using the following code,
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
i am using following code to display remote image with next and previous buttons.
I am using following code to display bitmap in my ImageView. When I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.