1
所以我明白如何從日期選取器中取出日期就好了。但我似乎無法將它從UIActionSheet上的日期選擇器中拉出來。我們目前的設置是一種使用少數選取器輸入數據的表單,它們都使用數據源的didSelectRow方法,所有這些方法都使用相同的視圖來表示數據源。UIDatePicker,UIActionSheet和數據處理
現在這似乎不適用於UIDatePicker。這是我迄今爲止的日期選擇器,它與我的其他選取器類似,包括處理值更改的方法。
-(IBAction)ageBox{
pickerAction=[[UIActionSheet alloc]initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[pickerAction setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
UIDatePicker *datePicker =[[UIDatePicker alloc]initWithFrame:pickerFrame];
[pickerAction addSubview:datePicker];
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];
date = datePicker.date;
[closeButton addTarget:self action:@selector(closePicker) forControlEvents:UIControlEventValueChanged];
[pickerAction addSubview:closeButton];
whatToChange = 5;
[pickerAction showInView:self.view];
[pickerAction setBounds:CGRectMake(0, 0, 320, 464)];
}
任何從日期選取器拉動的日期,而它的動作片,或當我它摧毀之前單擊確定,從它拉它的幫助嗎?
第二工作就像一個魅力。我添加了NSDateFormatter * df = [[NSDateFormatter alloc] init]; df.dateStyle = NSDateFormatterMediumStyle; date = [NSString stringWithFormat:@「%@」, [df stringFromDate:pickedDate]];爲了使它成爲我可以在其他地方設置的字符串。謝謝! –