8

我正在从画廊中挑选照片并保存在画廊中

我的代码是

-(void)onclicksave:(id)sender
{
    NSLog(@"onclicksave");
    UIImagePickerController *picker=[[UIImagePickerController alloc]init];
    picker.delegate=self;

    if((UIButton *)sender== openLibrary)
    {
        picker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    }
    else
    {
        picker.sourceType=UIImagePickerControllerSourceTypeCamera;
    }

    [self presentModalViewController:picker animated:YES];

}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissModalViewControllerAnimated:YES];
    imagedisplay.image=[info objectForKey:@"UIImagePickerControllerOriginalImage"];

}

但在这段代码中,运行时错误如

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“源类型 1 不可用”

所以给出适用于我的代码的任何建议和源代码

4

1 回答 1

17

嗯,这就是它所说的。UIImagePickerControllerSourceTypeCamera是来自枚举的值,等于 1。您正在尝试在没有摄像头的模拟器或设备上运行代码。

于 2012-05-21T13:45:41.090 回答