I am making a simple iOS notes application just to learn, and I wanted to add a simple date when the notes are created. Kinda like the default notes.app. This is what I have tried so far:
I have created a label in the storyboard and made it into a property and synthesized it. This is my code
- (void)configureCell:(IdeasTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
...
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat: @"yyyy-MM-dd HH:mm:ss zzz"];
NSDate *dateTmp;
cell.dateLabel.text = [dateFormat stringFromDate:dateTmp];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
It keeps returning an error… any ideas on what is causing the problem? Sorry, for the dumb question, but I have just started iOS dev.
The reason you get a crash is that the NSDate* object is not initialized. You need to assign it an instance representing the current date: