Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

John Baughman

macrumors regular
Original poster
Oct 27, 2003
100
0
I am having trouble making this work...

Code:
cell.detailTextLabel.text = [NSString stringWithFormat:@"%ihrs West",[[statusInfo objectAtIndex:indexPath.row] unsignedIntValue]];

The object in the statusInfo array is an NSNumber. If it contains the value -2, I want the cell.detailText.text to display 2hrs West. Instead I am getting -2hrs West. I can't figure out how to get the absolute value of the integer stored in the NSNumber. I have tried a lot of different things, but the above code seems to me to be the way to do it. What am I doing wrong.

John
 
You could just do a dirty hack and multiply the value by -1 if the value is negative

OR

You could use the c abs function on the value from the from the row,
Code:
cell.detailTextLabel.text = [NSString stringWithFormat:@"%ihrs West",abs([[statusInfo objectAtIndex:indexPath.row] intValue])];
I think this should work.
 
thanks!! The abs function worked great.

I jumped into Objective-C never having done any c programming. I really need to take a time out and review what is available in c and how to use it in Cocoa.

Thanks again,

John
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.