-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
以前都是用這個方法擷取點擊事件,然後彈出 UIImagePickerController 但是IOS8後在iPad上此方法不能正確彈出了;
原因:UIActionSheet改父於UIAlertController,所以彈出 UIImagePickerController時因為已經有actionsheet存在了,不能present新的。
解決方案:不調用以前舊方法,調用 方法
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if(buttonIndex==actionSheet.cancelButtonIndex){return;}
//照相 或 從相簿選取
UIImagePickerControllerSourceType type = UIImagePickerControllerSourceTypePhotoLibrary;
if([UIImagePickerController isSourceTypeAvailable:type])
{
if(buttonIndex==0 && [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
type = UIImagePickerControllerSourceTypeCamera;
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = NO;
picker.delegate = self;
picker.sourceType = type;
[self presentViewController:picker animated:YES completion:nil];
} }
評論是一種美德,是對作者的一種鼓勵,歡迎斧正,謝謝。