0

我正在该应用程序中创建一个应用程序,其中我在 UITextView 中显示日期。并且应该从 UIDatepicker 中选择该文本,但是我想在用户开始编辑 textview 并从日历中选择日期时显示日历而不是 UIDatepicker,并且该日期将显示在 textview 中。我怎样才能做到这一点?苹果允许吗?代码会更好。

4

4 回答 4

0

使用以下两个委托方法

 -(void)textViewDidBeginEditing:(UITextView *)textView 
 //type required code here to start date picket.

 -(void)textViewDidEndEditing:(UITextView *)textView
 //type required code here when user done with editing
于 2013-03-21T05:48:56.820 回答
0

在委托方法中

    -(void)textViewDidBeginEditing:(UITextView *)textView {
     //show the calendar
}

在日历的操作方法中,将日期设置textView.text为选定日期

于 2013-03-21T05:57:25.823 回答
0

你可以这样做:

NSString *stringDate=[self.textField text];
NSDateFormatter *dateFormatter=[NSDateFormatter new];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];
NSDate *dateFromText=[dateFormatter dateFromString:stringDate];

[self.datePicker setDate:dateFromText];

注意:您需要验证用户输入的日期应为特定格式。 从按钮操作或委托中调用上述代码。

于 2013-03-21T05:58:27.477 回答
0

对于显示弹出日历,您可以使用PMCalendarOCCalendar链接。这将像这样显示日历:

在此处输入图像描述

还有这个 :

在此处输入图像描述

于 2013-03-21T06:20:37.767 回答