In header file I have:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (IBAction)displayDay:(id)sender;
@property (weak, nonatomic) IBOutlet UIDatePicker *datePicker;
@end
Implementation:
- (IBAction)displayDay:(id)sender {
NSDate *chosen = [UIDatePicker date];
}
Xcode is telling me I should have UIdatePicker, but when I make that change it says "No know class method for selector 'date'".
Any advice on how to deal with this?
The following code won't work:
NSDate *chosen = [UIDatePicker date];
Because the date
is not a class method it's a property of UIDatePicker class.
date
The date displayed by the date picker.
@property(nonatomic, retain) NSDate *date;
Discussion
The default is the date when the UIDatePicker object is created. The date is ignored in the mode UIDatePickerModeCountDownTimer; for that mode, the date picker starts at 0:00. Setting this property does not animate the date picker by spinning the wheels to the new date and time; to do that you must use the setDate:animated: method.
You need to use it like:
NSDate *chosen = [datePicker date];
Do like this
- (IBAction)displayDay:(id)sender
{
NSDate *chosen = [self.datePicker date];
}
- (IBAction)displayDay:(id)sender {
NSDate *chosen = [yourdatepicker date];
NSLog(@"%@",chosen);
}
try like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With