Gold challenge solution


#1

I just solved the gold challenge. Pls examine the solution. Any improvement tips or suggestions would be welcome. Pls feel free to point out mistakes or shortcomings in the code or any implementation.

DetailViewController.m

-(IBAction)changeDate:(id)sender{
    
    DateViewController *dateViewController= [[DateViewController alloc] init];
    dateViewController.item=_item;
    [self.navigationController pushViewController:dateViewController animated:YES];
}

DateViewController.h

#import <UIKit/UIKit.h>
@class BNRItem;
@interface DateViewController : UIViewController
{
   IBOutlet UIDatePicker *datePicker;
}
@property BNRItem *item;
@property NSDate *date;
-(void)configure;
@end
#import "DateViewController.h"
#import "BNRItem.h"
@interface DateViewController ()

@end

@implementation DateViewController
@synthesize item=_item;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    NSLog(@"DateView loaded");
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
}
-(void)viewDidAppear:(BOOL)animated{
    NSLog(@"DateView appeared");
    [super viewDidAppear];
    [datePicker setDatePickerMode:UIDatePickerModeDate];
    [datePicker addTarget:self action:@selector(configure) forControlEvents:UIControlEventValueChanged];
    
}
-(void)viewDidDisappear:(BOOL)animated{
    NSLog(@"DateView disappeared");
    [super viewDidDisappear];
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)configure{
    NSLog(@"Date- %@",[datePicker date]);
    self.item->dateCreated= [datePicker date];
}
@end

As you can see i did a target-action implementation using the addTarget:action:forControlEvents. Please tell me if this is a good enough approach to solving the challenge. There’s a thing that did not understand-The insurance fraud label that we had to put. Whats that all about?? One plus point that i have in this is that i need not have to update the dateLabel when i come back from DateViewController’s view to the DetailViewController’s view. Anyways any suggestions are welcome. :slight_smile:


#2

Thanks for posting your solution. It really helped me understand what is going on in this challenge.

John