Regarding the Gold Challenge



I’ve just finished the Gold Challenge. I’d love to see what everyone else has put up. In the meantime, you can check out how I’ve put this together.

My methodology:
[ul]Create a new class, BNRChangeDateController, with xib.
Create a button in BNRItemsViewController, with the label 'Change Date’
Import BNRChangeDateController into BNRItemsViewController
Modify Xibs
Create a pointer in the button to the current BNRItem displayed in BNRDetailViewcontroller
Connect everything up!


@class BNRItem;

@interface BNRChangeDateController : UIViewController
@property (nonatomic, strong) BNRItem *theItem;


[code]#import “BNRChangeDateController.h”
#import “BNRItem.h”

@interface BNRChangeDateController ()
@property (weak, nonatomic) IBOutlet UIDatePicker *theNewDatePicker;

@implementation BNRChangeDateController

  • (void) viewWillAppear:(BOOL)animated
    [super viewWillAppear];
    //BNRItem *theItem = self.theItem;


  • (void) viewWillDisappear:(BOOL)animated
    [super viewWillDisappear];

    //Clear first responder
    [self.view endEditing:YES];

    BNRItem *theItem = self.theItem;
    [theItem changeDate:];


Button ‘Change Date’:

[code]- (IBAction) changeTheDate:(id)sender
BNRChangeDateController *changeDateController = [[BNRChangeDateController alloc] init];
changeDateController.theItem = self.item;
[self.navigationController pushViewController: changeDateController animated:YES];


That’s pretty much it! Let me know if you got to the same conclustion


I did mine in a slightly different way from you.
EDIT: I tried it your way too and I guess your way is more elegant.

  1. Created class BNRDateViewController with xib.

BNRDateViewController.xib contains only a UIDatePicker. Connected UIDatePicker to IBOutlet property in .h (to make it public). Other than this, my BNRDateViewController.h and BNRDateViewController.m file is completely blank.

@interface BNRDateViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIDatePicker *datePicked;
  1. Created ‘Change date’ button in BNRDetailViewController.xib
    Corresponding IBAction method in BNRDetailViewController.m:
// Create instance of BNRDateViewController as a property.
@property (nonatomic) BNRDateViewController *dateViewController;
// Method implemented when button is clicked
- (IBAction)changeDate:(id)sender
    self.dateViewController = [[BNRDateViewController alloc] init];
    // Push it to the top of the navigation controller's stack
    [self.navigationController pushViewController:self.dateViewController animated:YES];

This creates the instance of dateViewController and pushes it to the top of the stack when the button is clicked.

  1. Modify viewWillappear: in BNRDetailViewController.m
- (void)viewWillAppear:(BOOL)animated
    if (self.dateViewController.datePicked) {
        self.dateLabel.text = [dateFormatter];
        item.dateCreated =;
    } else {
        self.dateLabel.text = [dateFormatter stringFromDate:item.dateCreated];

When dateViewController is popped off the stack, this method is called again. if the datePicked property in dateViewController has been created, display that value then ‘save’ it in item. Else do what it did before.