这是我到目前为止所拥有的……
- (IBAction)showDatePicker { CGRect frame = CGRectMake(200,self.vIEw.frame.size.height,self.vIEw.frame.size.wIDth,0); //CGRectMake(225,145,260,125); UIPickerVIEw *datePicker = [[UIPickerVIEw alloc] initWithFrame:frame]; UIAlertVIEw *showDatealert = [[UIAlertVIEw alloc] initWithTitle:@"Enter the Code Date" message:@"Sample message" delegate:self cancelbuttonTitle:@"Cancel" otherbuttonTitles:@"Update",nil]; [self.vIEw addSubvIEw:datePicker]; [UIVIEw beginAnimations:@"slIDeIn" context:nil]; [datePicker setCenter:CGPointMake(datePicker.frame.origin.x,self.vIEw.frame.size.height - datePicker.frame.size.height/2)]; [UIVIEw commitAnimations];}
我发现了一个似乎正在工作的示例但我没有在警报框中看到任何对话框或按钮,只有日期选择器本身.我在这里错过了什么吗?
- (IBAction)showDatePicker { CGRect frame = CGRectMake(225,125); UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:frame]; datePicker = [[UIDatePicker alloc] init]; datePicker.datePickerMode = UIDatePickerModeDate; [datePicker setDate:[NSDate date]]; UIAlertVIEw *alert; alert = [[UIAlertVIEw alloc] initWithTitle:@"Enter the Code Date" message:@"Sample message" delegate:self cancelbuttonTitle:@"Cancel" otherbuttonTitles:@"Update",nil]; alert.delegate = self; [alert addSubvIEw:datePicker]; [alert show];}解决方法 我同意那些一直说这不是实现这个目的的评论者,原因有两个.首先,没有人喜欢不断出现警报视图.其次,并不适用于您的情况,最终可能会导致应用被拒绝. Apple更改了UIAlertVIEw类引用中的措辞,将其视图层次结构视为私有;而且我们都知道苹果如何看待你在他们认为私密的东西.
From UIAlertVIEw class reference:
The UIAlertVIEw class is intended to be used as-is and does not
support subclassing. The vIEw hIErarchy for this class is private and
must not be modifIEd.
但既然你说这是一个私人应用程序,那么就这样吧. UIAlertVIEw只是一个UIVIEw子类.所以帧和边界的所有规则仍然适用.以下是如何调整选择器框架和警报范围以挤入日期选择器的基本示例.
// Create alertUIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Hello" message:@"message" delegate:self cancelbuttonTitle:@"Cancel" otherbuttonTitles:@"OK",nil];// Show alert (required for sizes to be available)[alert show];// Create date picker (Could / should be an ivar)UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(10,alert.bounds.size.height,320,216)];// Add picker to alert[alert addSubvIEw:picker];// Adjust the alerts boundsalert.bounds = CGRectMake(0,320 + 20,alert.bounds.size.height + 216 + 20);
编辑
正如许多“我如何向UIAlertVIEw添加一些视图”的评论和新答案所指出的那样,这种方法在iOS7及更高版本中不再适用.这应该被视为这是一个根本不好的想法的证据.
还要注意setValue:forKey的用法:在一般流通的“解决方案”中解决了无法修改Apple的私有视图层次结构的“问题”. setValue:forKey:是引起私有API扫描程序兴趣的方法之一.在UIAlertVIEw文档和标题中搜索accessoryVIEw.它不在文档中.标题中唯一相关的项目是名为_accessoryVIEw的ivar,标记为@private.
再次对于内部或私人应用程序,我认为它没关系,但是没关系.
总结以上是内存溢出为你收集整理的ios – 将UIDatePicker添加到UIAlertView全部内容,希望文章能够帮你解决ios – 将UIDatePicker添加到UIAlertView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)