2 つの日付ピッカーと 1 つのボタンがあります。ピッカーから日付を選択すると、最初のピッカーが 2 番目のピッカーの値を取得します。
出力ログ
< dt1 > 20.05.2013 </ dt1 > 最初のピッカー
< dt2 > 20.05.2013 < /dt2 > セカンドピッカー
.h
-(IBAction)Send:(UIButton *)sender;
@property (nonatomic, retain) IBOutlet UITextField *Date1;
@property (nonatomic, retain) IBOutlet UITextField *Date2;
.m
-(IBAction)Send:(UIButton *)sender{
NSString *mensagemSOAP= [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"
"<UrunToplamiGetir xmlns=\"http://tempuri.org/\">\n"
"<dt1>%@</dt1>\n"
"<dt2>%@</dt2>\n"
"</UrunToplamiGetir>\n"
"</soap:Body>\n"
"</soap:Envelope>\n",Date1.text,Date2.text];
NSLog(@"SOAP Message= \n%@\n\n", mensagemSOAP);
NSURL *url = [NSURL URLWithString:@"http://95.0.50.18:1249/kayit.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *tamanhoMensagem = [NSString stringWithFormat:@"%d", [mensagemSOAP length]];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/UrunToplamiGetir"
forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:tamanhoMensagem forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[mensagemSOAP dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conexao = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(conexao){
webData = [NSMutableData data];
}else{
NSLog(@"Connection Error.");
}
}
- (void)addInputViewToTextField:(UITextField *)textField{
if (!_datePicker) {
_datePicker = [[UIDatePicker alloc]init];
//[_datePicker setTag:textField.tag];
[_datePicker setTag:Date1.tag];
[_datePicker setTag:Date2.tag];
[_datePicker setDatePickerMode:UIDatePickerModeDate];
[_datePicker setDate:[NSDate date]];
}
Date1.inputView = _datePicker;
Date2.inputView=_datePicker;
_autocompleteTextField.inputView=nil;
if (!_pickerToolBar) {
_pickerToolBar =[[UIToolbar alloc]initWithFrame:CGRectMake(0,0,
self.view.frame.size.width,44)];
_pickerToolBar.barStyle =UIBarStyleBlackOpaque;
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@selector(cancelButtonPressed:)];
UIBarButtonItem *flexibleSpace =[[UIBarButtonItem
alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self
action:nil];
UIBarButtonItem *doneButton =[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self
action:@selector(doneButtonPressed:)];
[_pickerToolBar setItems:@[cancelButton,flexibleSpace, doneButton]];
}
textField.inputAccessoryView = _pickerToolBar;
}
-(void)doneButtonPressed:(id)sender{
if (!_dateFormatter) {
_dateFormatter = [NSDateFormatter new];
[_dateFormatter setDateFormat:@"dd.MM.yyyy"];
}
Date1.text = [_dateFormatter stringFromDate:_datePicker.date];
[Date1 resignFirstResponder];
Date2.text = [_dateFormatter stringFromDate:_datePicker.date];
[Date2 resignFirstResponder];
}
- (void)cancelButtonPressed:(id)sender{
[Date1 resignFirstResponder];
[Date2 resignFirstResponder];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
Date1 = textField;
Date2 = textField;
[self addInputViewToTextField:textField];
[self addInputViewToTextField:textField];
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
}
私の間違いはどこですか?