UIDatePickerView issue since upgrade to ios 8

Ive just updated to iOS 8 and I have a problem with my app, everything except the date makers in the worksheet. When an action is selected to display an action sheet along with a date picker added as a subview, the application will crash. I found the problem code which:

-(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

}

      

The console log produces the following:

-[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]' 

      

Earlier I solved (badly) by changing each index to 2 and 3, which worked but was a messy implementation.

This is the actual implementation:

-(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"];

}

      

If I remove the problem code the action sheet is shown, but now there is no date picker. (I do not know why)

Any ideas on how to fix this?

Thank you in advance

+3


source to share


2 answers


Maybe apple will change the view hierarchy, there is a note in the docs that doesn't really apply to your case, but still gives us a hint of what's going on:

UIActionSheet is not meant to be subclassed and you shouldn't add views to your hierarchy. If you need to present a sheet with more customization than the provided UIActionSheet API, you can create your own and present it modally using currentViewController: animated: completion :.



Just like with apple UIAlerView, we don't want us to change its experience. There because they did a little bit of a hierarchy of views.

The smartest solution would be to do as apple suggested: create your own single view controller and present it differently.

+2


source


In iOS 8. Change slide in UIActionSheet. Try this code.



UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];

[alert.view addSubview:theDatePicker];   
[self presentViewController:alert animated:YES completion:nil];

      

0


source







All Articles