0
私はdatepickerをトリガするテキストフィールドをたくさん見ました。 私はdatepickerを作る方法を1つだけ持ちたいと思う。このdatepickerには、テキストフィールドの識別子を持つメソッドセレクタが必要です。私はどうすればこれを作ることができるのか分かりません。argsを持つUIDatePickerのセレクタ(UITextfiled)
- (IBAction)launchPickerDate:(id)sender{
UIDatePicker *datepickerNew = [UIDatePicker new];
[datepickerNew setHidden:NO];
datepickerNew.frame = CGRectOffset(datepickerNew.frame, 0, 244);
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
UIDatePicker *launchPickerDate = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[launchPickerDate addTarget:self action:@selector(SelectDatePicker:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:launchPickerDate];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Ok"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(closeDatePicker:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
タグでいいですが、私のコードが '[launchPickerDate addTarget:self action:@selector SelectDatePicker :) forControlEvents:UIControlEventValueChanged]; ' –
これで問題ありません!全ての場合 : I追加した 'launchPickerDate.tag = sender.tag;' そして ' - (IBAction)SelectDatePicker:(UIDatePicker *)差出人{ UITextFieldの* TMP =(UITextFieldの*) [self.view viewWithTag:sender.tag]; NSDate * date = [送信者日付]; NSDateFormatter *フォーマッタ= [[NSDateFormatter alloc] init]; [フォーマッタsetDateFormat:@ "yyyy-MM-dd HH:mm"]; tmp.text = [フォーマッタstringFromDate:日付]; } ' –