Core Data Values to strings for UILabels

I have some values that are stored with core data, and I have opened the application's sqlite database to make sure that the values are being stored correctly, but when I try to display the values they come out all funky. I store the values from the core data entity in an array then try to call the values. Basically I am new to developing with objective c and think I need some formatting help. Here is the code block displaying the funky numbers on output:

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
NSString *dateString = [dateFormatter stringFromDate:dJournal.dateTime];

cell.dateLabel.text = dateString;
cell.insulinTypeLabel.text = dJournal.insulinType; 
cell.glucoseLevelLabel.text = [NSString stringWithFormat:@"%e",dJournal.glucoseLevel ];
cell.carbTotalLabel.text = [NSString stringWithFormat:@"%d",dJournal.carbTotal ];
cell.insulinAmountLabel.text = [NSString stringWithFormat:@"%E",dJournal.insulinUnits ];

return cell;

Here is the core data generated class file:

@property (nonatomic, retain) NSDate * dateTime;
@property (nonatomic, retain) NSNumber * glucoseLevel; //Double
@property (nonatomic, retain) NSString * insulinType;  //string - no problem with
@property (nonatomic, retain) NSNumber * insulinUnits; //Double
@property (nonatomic, retain) NSNumber * carbTotal; //Integer64

I also have tried:

[[NSNumber numberWithInt:carbTotal] stringValue]

no luck. Thanks in advance for any help.

Answers


Why are you using %e, %d etc? If you want to print out objective-C objects you need to use the %@ format specifier, e.g.

cell.glucoseLevelLabel.text = [NSString stringWithFormat:@"%@", dJournal.glucoseLevel];

If you are displaying numbers however, you should actually be using an instance of NSNumberFormatter to generate locale-aware strings.


You are using wrong specifier. Try to use

 [NSString stringWithFormate:@"%@",your_string];
 [NSString stringWithFormate:@"%d",your_integer];
 [NSString stringWithFormate:@"%.02f",your_float]; 

.02 indicates up to which place after decimal you want


Need Your Help

Python and Pandas - Removing footer in multiple files with the same break

python excel pandas footer

I am doing data analysis on a group of different excel files, each with a footer. The start point of the footer changes based on the total number of rows. The footer starts in the first column as a...

Column 'columnName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause

sql sql-server optimization

I have two database tables, project and story. The one project having different types of story. I wanted to display all project with each type story count.