2012-01-31 89 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