【问题标题】:Test ipad 2 camera with xcode simulator IOS 5使用 xcode 模拟器 IOS 5 测试 ipad 2 摄像头
【发布时间】:2012-01-31 05:07:02
【问题描述】:

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

  -(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' 

但它在 4.3 模拟器上工作

【问题讨论】:

    标签: ios ipad camera uiimagepickercontroller


    【解决方案1】:

    从 iOS5 开始,您需要在弹出视图而不是模态视图中显示选择器控制器。

    来自苹果文档:在 iPad 上,使用弹出框呈现用户界面。仅当图像选择器控制器的 sourceType 属性设置为 UIImagePickerControllerSourceTypeCamera 时,这样做才有效。要使用 popover 控制器,请使用 UIPopoverController 类参考中“Presenting and Dismissing the Popover”中描述的方法。

    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];
    

    【讨论】:

    • 谢谢,第 2 行有警告。如果我使用 imagePicker.delegate = (id)self 可以吗;
    猜你喜欢
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    相关资源
    最近更新 更多