UIDatePicker、UIActionSheet 和数据处理
所以我知道如何从日期选择器中提取日期。但我似乎无法从 UIActionSheet 上的日期选择器中提取它。我们当前的设置是一个使用几个选择器输入数据的表单,所有选择器都使用数据源的 didSelectRow 方法,并且所有选择器都使用相同的视图来表示数据源。
现在看来,这对于 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)];
}
当日期位于操作表上时,或者当我单击“确定”时,在日期选择器被销毁之前从日期选择器中提取日期,有什么帮助吗?
So I understand how to pull the date from a date picker just fine. But I can't seem to be able to pull it from a date picker on a UIActionSheet. Our current set up is a form for entering data with a few pickers, all using the didSelectRow method for the data source, all of them using the same view for said data source.
Now this doesn't work for a UIDatePicker in the same way, it seems. Here is what I have so far for my date picker, it's similar to my other pickers, including the methods to handle changing of values.
-(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)];
}
Any help pulling the date from the date picker while it's on the action sheet, or when I click ok, pulling it from it before it's destroyed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据方法中的第一行代码,我假设
pickerAction
是self
的ivar
。我可以想到几种方法,我相信还有更多。1) 将
datePicker
也设为ivar
。这样您就可以为您的'ok'
方法引用它。2) 从
pickerAction
本身获取引用。由于您已将datePicker
添加为subview
,因此您可以像这样找到它:I'm making the assumption that
pickerAction
is anivar
ofself
, based on the first line of code in the method. I can think of a couple of ways, I'm sure there are more.1) Make
datePicker
anivar
as well. That way you have a reference to it for your'ok'
method.2) Obtain the reference from the
pickerAction
itself. Since you have added thedatePicker
as asubview
, you can find it like so: