我刚刚更新到iOS 8,我的应用程序有问题,除了操作工作表上的日期选取器。当为了显示操作表而将操作选择为与子视图一起添加的日期选择器时,应用程序会崩溃。我发现这个问题的代码,其是:UIDatePickerView问题,因为更新到ios 8
-(void)willPresentActionSheet:(UIActionSheet*)actionSheet{
theDatePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 40, 320, 216)];
[actionSheet addSubview:theDatePicker];
NSArray *subviews = [actionSheet subviews];
[[subviews objectAtIndex:0]setFrame:CGRectMake(20, 266, 280, 46)]; //this line
[[subviews objectAtIndex:1]setFrame:CGRectMake(20, 317, 280, 46)]; //also this one
}
控制台日志产生这样的:
-[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
以前我解决了它(严重)通过改变每个索引2 & 3,其工作,但是一个凌乱的实施。
这是实际执行:
-(void)willPresentActionSheet:(UIActionSheet*)actionSheet{
theDatePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 40, 320, 216)];
[actionSheet addSubview:theDatePicker];
NSArray *subviews = [actionSheet subviews];
[[subviews objectAtIndex:0]setFrame:CGRectMake(20, 266, 280, 46)];
[[subviews objectAtIndex:1]setFrame:CGRectMake(20, 317, 280, 46)];
}
-(void)datePickerViewFromInput:(NSString*)title{
SheetPicker=[[UIActionSheet alloc]initWithTitle: title delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Set", nil];
[SheetPicker showInView:self.view ];
[SheetPicker setFrame:CGRectMake(0,117, 325, 383)];
theDatePicker.datePickerMode = UIDatePickerModeDate;
NSDateFormatter *Formatter = [[NSDateFormatter alloc]init];
[Formatter setDateFormat:@"MM/dd/yyyy"];
}
如果我删除的问题代码,动作片将显示,但已不再是一个日期选择器。 (我不知道为什么)
有关如何解决此问题的任何想法?
在此先感谢
辉煌,谢谢。 – TinMan7757 2014-09-19 10:13:47