I have seen other posts on this subject, but this seems different.
I am building an iPhone app based on the CoreDataBooks example. In my PatientDetailViewController, the date does not appear in the appropriate row – appearing null when there is obviously data. I have searched in the headers, xib and elsewhere to find why the sample works and mine does not – and I am not making any progress.
Note that dateOfBirth is an attribute of Patient in the model.
In the interface I have
@class Patient;
@class EditingViewController;
#include <UIKit/UIKit.h>
@interface PatientDetailViewController : UITableViewController {
Patient *patient;
NSDateFormatter *dateFormatter;
}
@property (nonatomic, retain) Patient *patient;
@property (nonatomic, retain) NSDateFormatter *dateFormatter;
@end
Here is the code in my tableView: cellForRowAtIndexPath:
...
cell.textLabel.text = @"DOB";
cell.detailTextLabel.text = [self.dateFormatter stringFromDate:patient.dateOfBirth];
NSLog(@"the formatted date is %@", [self.dateFormatter stringFromDate:patient.dateOfBirth]);
NSDate *date = [patient valueForKey:@"dateOfBirth"];
NSLog(@"the date is %@", date);
...
And the output on the console is as follows:
2011-01-02 18:02:27.484 App[3633:207] the formatted date is (null)
2011-01-02 18:02:27.487 App[3633:207] the date is 1993-01-02 17:41:46 -0800
I would appreciate any assistance. Thanks.
Did you allocate it somewhere?
You can place this in
viewDidLoador wherever it is convenient for you. Just make sure that this line is called before you actually usedateFormatter.