我有方法,从画廊或相机拍照
-(IBAction) getPhoto:(id) sender { UIImagePickerController * picker = [[UIImagePickerController alloc] init]; picker.delegate = self; if((UIButton *) sender == choosePhotoBtn) { picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; } else { picker.sourceType = UIImagePickerControllerSourceTypeCamera; } [self presentModalViewController:picker animated:YES]; }
但是当我在模拟器上运行它时,代码不起作用.并且它在picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum和picker.sourceType = UIImagePickerControllerSourceTypeCamera中不起作用
是模拟器还是代码中的问题?
解决方法
试试这个,
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; } else { picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; } [self.navigationController presentModalViewController:picker animated:NO];
如果您要为iPad创建应用程序.您必须在popOver控件中显示库.