2012-01-30 10 views
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)]; 

} 

答えて

0

私は本当にあなたの質問を取得していないが、それはあなたが選択したテキストフィールドに基づいて、あなたの日付ピッカーにいくつかの変更をしたい私には思える:

は、ここに私のコードです。 tagプロパティを使用して、メソッドが呼び出されたテキストフィールドを認識できます。 Like

if (sender.tag==1){ 
//do something as first text field selected 
}else if(sender.tag==2){ 

//do something as second text field selected 
} 

テキストフィールドのタグは、インターフェイスビルダー(xibを使用している場合)またはコードのように指定できます。 firstTextField.tag=1; など..これが役に立ったら...

+0

タグでいいですが、私のコードが '[launchPickerDate addTarget:self action:@selector SelectDatePicker :) forControlEvents:UIControlEventValueChanged]; ' –

+0

これで問題ありません!全ての場合 : 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:日付]; } ' –

関連する問題