-2
我有一些文本字段已填寫,然後用於使用NSString填充電子郵件正文。我已經完成了與日期選取器的文本字段相同的代碼,但它不是一個輸出字符串,所以NSString不起作用。我曾嘗試使用NSDate,但不知道如何像其他人一樣獲取此內容。這是代碼:如何將DatePicker數據導入電子郵件正文
Delaring變量:
@interface HomeView()<MFMailComposeViewControllerDelegate,UITextFieldDelegate>
{
IBOutlet UITextField *txtClient;
IBOutlet UITextField *txtTime;
IBOutlet UITextView *txtNotes;
IBOutlet UITextView *txtHardware;
IBOutlet UIDatePicker *txtDate;
}
@end
填充電子郵件:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:[userDefault objectForKey:@"Subject"]];
[picker setToRecipients:[NSArray arrayWithObject:[userDefault objectForKey:@"Email"]]];
NSString *string=[NSString stringWithFormat:@"Client: %@\n Time: %@ \n\n Notes: \n %@ \n Hardware: \n %@",txtClient.text,txtTime.text,txtNotes.text,txtHardware.text];
txtClient.text = @"";
txtTime.text = @"";
txtNotes.text = @"";
txtHardware.text = @"";
[picker setMessageBody:string isHTML:NO];
[self presentViewController:picker animated:YES completion:^{
//Not working - input date data
//NSDATE *string=[NSString stringwithformat:@Date: %@",txtDate.date];
//txtDate.date = @"";
}];
在此先感謝。
什麼是您的具體問題?你不知道如何從日期選擇器獲取日期,或者如何將日期轉換爲字符串? – rdelmar 2014-09-28 23:42:40
在一個代表我的代言人的巨大時刻,我沒有想過將它轉換爲一個字符串..所以,這個問題會將它從一個日期轉換爲字符串 – Weighsone 2014-09-28 23:56:23
NSDateformatter? – Paulw11 2014-09-29 00:00:31