Add UIPickerView in UIActionSheet from IOS 8 not working
Solution 1:
Per the Apple docs,
Important:
UIActionSheet
is deprecated in iOS 8. (Note thatUIActionSheetDelegate
is also deprecated.) To create and manage action sheets in iOS 8 and later, instead useUIAlertController
with apreferredStyle
ofUIAlertControllerStyleActionSheet
.
Link to documentation for UIAlertController
For example:
UIAlertController * searchActionSheet=[UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
[ searchActionSheet.view setBounds:CGRectMake(7, 180, self.view.frame.size.width, 470)];
//yourView represent the view that contains UIPickerView and toolbar
[searchActionSheet.view addSubview:self.yourView];
[self presentViewController:searchActionSheet animated:YES completion:nil];
Solution 2:
It doesn't work because Apple changed internal implementation of UIActionSheet
. Please refer to the documentation:
Subclassing Notes
UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy. If you need to present a sheet with more customization than provided by the UIActionSheet API, you can create your own and present it modally with presentViewController:animated:completion:.