2012-01-31 51 views
1

我正在测试ipad相机应用程序与ipad模拟器 我使用下面的代码,更改源类型而不是相机。测试ipad 2相机与xcode模拟器IOS 5

-(IBAction)useCamera:(id)sender{ 


    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){ 

    UIImagePickerController *imagePicker = 
    [[UIImagePickerController alloc] init]; 
    imagePicker.delegate =(id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>) self; 
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil]; 
    imagePicker.allowsEditing = NO; 
    [self presentModalViewController:imagePicker animated:YES]; 

    [imagePicker release]; 
    newMedia = YES; 

    } 

}

当在模拟器中运行错误在iOS 5中的模拟器上来。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'On iPad,  UIImagePickerController must be presented via UIPopoverController' 

但随着iOS5的其对4.3模拟器

回答

2

工作开始,你需要显示在酥料饼的视图,而不是一个模式视图pickercontroller。

从苹果文档:在iPad上,使用popover显示用户界面。这样做仅在图像选取器控制器的sourceType属性设置为UIImagePickerControllerSourceTypeCamera时有效。要使用popover控制器,请使用UIPopoverController类参考中的“呈现和取消弹出窗口”中介绍的方法。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

这里是呈现的UIImagePickerController一个酥料饼的视图内的示例:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
imagePicker.delegate = self; 
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0) 
        inView:self.view 
        permittedArrowDirections:UIPopoverArrowDirectionAny 
        animated:YES]; 
+0

谢谢,有在第2行的警告它是确定如果我使用imagePicker.delegate =(ID )自我; – Susitha 2012-01-31 06:34:52