开发者

Setting the date for DatePicker in another class?

开发者 https://www.devze.com 2023-03-11 08:48 出处:网络
//inside New_Entry.h IBOutlet UIDatePicker *timePicker; @property (nonatomic, retain) UIDatePicker *timePicker;
//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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号