Search
Rich's Mad Rants
Powered by Squarespace

Creating iOS 5 Apps Discussion > Chapter 4 - DetailViewController weight values in kg

The weight entry when unit is set to kg is displayed incorrectly at the DetailViewController.
In the viewDidAppear method within the DetailViewController, all the stringForWeightInLbs:inUnit: method should be replaced by stringForWeight:ofUnit:, I think.

August 16, 2012 | Unregistered CommenterAlvin

I agree that something needs to change.
You chose the same change I made to get it working.
However, arguably the correct change is
to use the value in pounds to do the computations.
That is, instead of:

CGFloat sampleWeight = [entry weightInUnit:unit];

to get the values you would use

CGFloat sampleWeight = entry.weightInLbs;

August 23, 2012 | Unregistered CommenterCharlie Price

Sorry I didn't reply earlier, but I wanted to wait until I had time to really look at the code.

Good catch. When using Kg, it would convert the weight value twice. I'd recommend the solution proposed by Charlie Price, just change the weightInUnit: calls to weightInLbs.

Specifically, on line 73:

CGFloat weight = [currentEntry weightInLbs];

and on line 92:

CGFloat sampleWeight = [entry weightInLbs];

I hope that helps.

-Rich-

August 29, 2012 | Registered CommenterRichard Warren