gpt4 book ai didi

ios - 如何从 objective-c 中的日期选择器获取日期?

转载 作者:技术小花猫 更新时间:2023-10-29 11:15:11 27 4
gpt4 key购买 nike

在头文件中我有:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

- (IBAction)displayDay:(id)sender;
@property (weak, nonatomic) IBOutlet UIDatePicker *datePicker;

@end

实现:

- (IBAction)displayDay:(id)sender {

NSDate *chosen = [UIDatePicker date];

}

Xcode 告诉我应该使用 UIdatePicker,但是当我进行更改时它显示“不知道选择器‘日期’的类方法”。

关于如何处理这个问题有什么建议吗?

最佳答案

以下代码将不起作用:

NSDate *chosen = [UIDatePicker date];

因为 date 不是类方法,所以它是 UIDatePicker 的属性类。

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.

你需要像这样使用它:

NSDate *chosen = [datePicker date];

关于ios - 如何从 objective-c 中的日期选择器获取日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14700725/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com