Passing an NSDate

Posted by Garry on Stack Overflow See other posts from Stack Overflow or by Garry
Published on 2010-03-27T15:50:47Z Indexed on 2010/03/27 15:53 UTC
Read the original article Hit count: 390

I'm new to the iPhone and objective-c and I am still trying to get my head around ownership of objects so bear with me.

I have a DOBViewController that has a datepicker on it. I have created a custom init method:

-(id)initWithInitialDate(NSDate *)initialDate;

Another view controller has a date instance declared (NSDate *dob) that holds a value. I would like to pass this to the DOBViewController so that it can scroll the datepicker to the passed value.

Here is the custom init method:

- (id)initWithInitialDate:(NSDate *)initialDate {
// Initialise ourselves
self = [super init];

// Set the date of the date picker
if (initialDate != nil) {
    datePicker.date = initialDate;
}
else {
    // Set it to today
    datePicker.date = [NSDate date];
}

return self;

}

This is how I am sending the dob NSDate object:

DOBViewController *dobViewController = [[DOBViewController alloc] initWithInitialDate:dob];

Where dob is a variable of type NSDate that is declared in the header file.

This doesn't seem to work as initialDate is always NULL. What am I doing wrong?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about xcode