I have a problem with my getters and settings, they aren’t being called. I thought I understood how they worked, but it looks like I have a problem…
I know I’m not initializing the DateRangeController view before I use the select button, but knowing its nil I can set values in viewDidLoad. If I do have to initialize it how do I set the nib file etc ?
This is my parent screen, where I’m setting values and getting values
@interface PieChartViewController : UIViewController {
DateRangeController *nextController;
}
@property (nonatomic, retain) DateRangeController *nextController;
@implementation PieChartViewController
@synthesize nextController;
-(void)viewWillAppear:(BOOL)animated {
if ([nextController StartDate] == nil) {
[nextController setStartDate:[NSDate date]];
}
// DBStartDate returns nil and yes convertNSDateToDBStringDate works !
NSString* DBStartDate = [General convertNSDateToDBStringDate:
[nextController StartDate]];
}
- (void) selectRangeButtonPressed {
nextController = [[[DateRangeController alloc]
initWithNibName:@"DateRange" bundle:nil] autorelease];
nextController.title = @"Date Range";
}
Heres my selection / child screen.
@interface DateRangeController : UIViewController {
NSDate *returnStartDate;
}
-(NSDate*) StartDate;
-(void)setStartDate:(NSDate*) value;
@end
@implementation DateRangeController
-(NSDate*) StartDate {
return returnStartDate;
}
-(void)setStartDate:(NSDate*) value {
if (value != returnStartDate) {
[value retain];
[returnStartDate release];
returnStartDate = value;
NSLog(@"StartDate=%@", returnStartDate);
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)
nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
returnStartDate = nil;
}
return self;
}
- (void)dealloc {
[returnStartDate release];
}
try comparing “value” with the isEqualToDate – function instead of the “!=” – operator:
EDIT: If you need the nextController to store the startDate in the viewWillAppear, you should initialize it there (or, even better, in the viewDidLoad) and not in the buttonPressed – Method, before assigning the startDate.