我有2个文本框和1个按钮。我使用textfield输入日期,但我必须使用日期选择器。如何使用日期选择器而不是文本字段?
此代码用于输入日期到文本字段并显示一些字段到labels.How我更改日期选择器此代码?
ViewController.h
@interface ViewController : UIViewController <NSXMLParserDelegate>
- (IBAction)Send:(UIButton *)sender;
@property (unsafe_unretained, nonatomic) IBOutlet UITextField *Date1;
@property (unsafe_unretained, nonatomic) IBOutlet UITextField *Date2;
//will here define for date picker
@end
ViewController.m
@interface ViewController(){
NSMutableData *webData;
NSXMLParser *xmlParser;
NSMutableString *returnSOAP;
BOOL tReturn;
}
@end
@implementation ViewController
@synthesize Date1,Date2;
- (IBAction)Send:(UIButton *)sender{
NSString *msgSOAP= [NSString stringWithFormat:@"<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-
instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"<ShowDetails xmlns=\"http://tempuri.org/\">\n"
"<date1>%@</date1>\n"
"<date2>%@</date2>\n"
"</ShowDetails>\n"
"</soap:Body>\n"
"</soap:Envelope>\n",Date1.text,Date2.text];
NSLog(@"SOAP Resulr = \n%@\n\n", msgSOAP);
NSURL *url = [NSURL URLWithString:@"http://webservice/service.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *dnMsg = [NSString stringWithFormat:@"%d", [msgSOAP length]];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/ShowDetails"
forHTTPHeaderField:@"SOAPAction"];
[theRequest dnMsg forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[msgSOAP dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:theRequest
delegate:self];
if(con){
webData = [NSMutableData data];
}else{
NSLog(@"Connection Error.");
}
}
谢谢
什么是你想要的日期的格式?您需要使用textField的inputView和inputAccessoryView来显示一个datePicker。选择一个日期,使用dateFormatter将其转换并将其设置为textField的文本。 – Anupdas 2013-05-09 16:16:25