【问题标题】:iPhone app run in iPad Retina with image Picker but image picker Object is niliPhone应用程序在iPad Retina中运行,带有图像选择器,但图像选择器对象为零
【发布时间】:2014-09-23 08:55:55
【问题描述】:

这是 iPhone 应用程序代码,但是当我遇到 ipad 视网膜模拟器或
ipad 时,应用程序就会崩溃。我已经检查了很多次,我意识到
选择器对象为零。但它在 iPhone 模拟器上效果很好。任何人对这件事有任何想法。(这个应用程序只制作了 iPhone,但在 iPad Retina 和 iPad 上运行)

UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init]; // image picker alloc 
imagePicker.delegate = self; // delegate call by self

imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //Pick image in Library
[self presentModalViewController:imagePicker animated:YES]; // OPen Library


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info                
{
    imgImage = info[UIImagePickerControllerOriginalImage]; //Get Orginial Images
    imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((imgImage), 0.9)]; // Jpg image format
    [picker dismissModalViewControllerAnimated:YES];
} // pick image from this method

【问题讨论】:

  • 当它崩溃时,调试器中显示的错误信息具体是什么?
  • *** 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'*** setObjectForKey: object cannot be nil (key: Image)' 如果你知道这件事,请帮助我。跨度>
  • 崩溃所在行的内容是什么?你能提供它(以及任何周围的线条,如果可能的话)?
  • 打印返回的 NSDictionary 也可能有助于调试目的,如下所示: NSLog(@"info = %@", info);
  • UIImage *myImage =[info objectForKey:UIImagePickerControllerOriginalImage];我得到了 nil myImage nil。并在其他线路上崩溃。

标签: objective-c iphone ios7 uiimageview ipad-2


【解决方案1】:

试试这个...当从库中选择图像或从相机拍摄图像时调用此方法。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    NSData *imgData = UIImagePNGRepresentation(image);

    [picker dismissModalViewControllerAnimated:YES];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}

【讨论】:

  • 错误:- *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“*** setObjectForKey:对象不能为 nil(键:图像)”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多