Setting the date for DatePicker in another class?
//inside New_Entry.h
IBOutlet UIDatePicker *timePicker;
@property (nonatomic, retain) UIDatePicker *timePicker;
//inside New_Entry.m
@synthesize timePicker;
开发者_如何学编程
//inside AppDelegate.m
#import "New_Entry.h"
-(void)applicationDidBecomeActive:(UIApplication *)application {
NSDate *todayDate;
todayDate = [[NSDate alloc]init];
New_Entry.timePicker.date = todayDate;
[todayDate release];
}
Got an error in "New_Entry.timePicker.date = todayDate;" How do I update the timePicker.date to now whenever the app becomes active? Whats the difference between "DidBecomeActive" and "DidEnterForeground"?
Edit:
In AppDelegate (applicationWillEnterForeground)
New_Entry *new_Entry_instance = [[New_Entry alloc]init];
new_Entry_instance.timePicker.date = [NSDate date];
This code fails because you are not calling timePicker.date on a valid instance of the New_Entry class.
To make this work you would have to do something like this:
New_Entry *new_entry_instance = [[New_Entry alloc] init];
new_entry_instance.timePicker.date = todayDate;
If you are unsure of why this is the way to do it then please ask.
精彩评论