Gold Challenge


#1

Hi
My solution to the gold challenge
Baically I am sending the whole item to the new controller, adjusting the date of it, and returning to the detail controller, and the deal is done. Quite simple actually.
I Added a BNRDateViewController file with xib file:
Actually the @class declaration is not necessary here as I have no public methods using the BNRItem, thus the compiler does not save time here i think?

The header file.

/
//  BNRDateViewController.h
//  Homepwner
//
//  Created by Lars Christoffersen on 10/04/14.
//  Copyright (c) 2014 Lars Christoffersen. All rights reserved.
//

#import <UIKit/UIKit.h>
@class BNRItem;

@interface BNRDateViewController : UIViewController
@property (nonatomic, strong) BNRItem *item;

@end

The implementation file

//
//  BNRDateViewController.m
//  Homepwner
//
//  Created by Lars Christoffersen on 10/04/14.
//  Copyright (c) 2014 Lars Christoffersen. All rights reserved.
//

#import "BNRDateViewController.h"
#import "BNRItem.h"

@interface BNRDateViewController ()
@property (nonatomic, weak) IBOutlet UIDatePicker *datePicker;
@end

@implementation BNRDateViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        UINavigationItem *navItem = self.navigationItem;
        navItem.title = @"Select Date";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear];
    self.datePicker.date =  self.item.dateCreated;
}

- (void) viewWillDisappear:(BOOL)animated
{
    //set the date of the item to the data of the datepicker
    _item.dateCreated = _datePicker.date;    
}

@end

On the BNRDetailViewController I add the button and pick up the action like this:

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

Simple actually.
I do like objective c more and more :slight_smile: