只有在使用以下代码时,我才会在iPad上收到一个错误/崩溃,iPhone工作正常。
它基本上是在试图加载图库来挑选图像时使用的。
调试错误是;“在iPad上,必须通过UIPopoverController‘呈现UIImagePickerController’”
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error accessing photo library"
message:@"Device does not support a photo library"
delegate:nil
cancelButtonTitle:@"Abort!"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
if (buttonIndex == 1) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType =UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error accessing Camera"
message:@"Device does not support a Camera"
delegate:nil
cancelButtonTitle:@"Abort!"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSLog(@"the info opf picker is %@",info);
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];
NSData *imageData;
if ([info objectForKey:UIImagePickerControllerEditedImage]) {
UIImage *image2=[info objectForKey:UIImagePickerControllerEditedImage];
//UIImage *myscaledImage=[self scaleImage:image2 toSize:CGSizeMake(18, 24)];
//imageData = UIImagePNGRepresentation(myscaledImage);
imageData=UIImageJPEGRepresentation(image2, .4);
NSLog(@"the lenght of the edited image data is %d",[imageData length]);
}
else {
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
//UIImage *myscaledImage=[self scaleImage:image toSize:CGSizeMake(18, 24)];
//imageData = UIImagePNGRepresentation(myscaledImage);
imageData=UIImageJPEGRepresentation(image, .6);
NSLog(@"the lenght of the image dataa is %d",[imageData length]);
}
NSDictionary *tempDict=[NSDictionary dictionaryWithObjectsAndKeys:imageData,@"Image",@"Theme",@"Cell_Text",nil];
// NSLog(@"the custom array%@ and the row =%d", customArray,currentCameraRow);
[customArray replaceObjectAtIndex:currentCameraRow withObject:tempDict];
[pool drain];
//NSLog(@"")
[self startThread];
[picker dismissModalViewControllerAnimated:YES];
[myCustomTableView reloadData];
NSLog(@"size of myObject: %zd", malloc_size(myCustomTableView));
}有没有人愿意帮忙完成上面的代码?我在猜测if/else语句,但不知道它会是什么以及放在哪里。
提前谢谢你,
克里斯
编辑- Ok我现在让它工作从画廊加载现在加载‘照片’在一个小窗口中,我可以选择,但是没有‘选择’或‘选择’按钮,如果我点击照片,没有勾选,说它是选中的,但它确实选择了它,但要取消,我点击窗口外…所以它是有效的,但我猜我遗漏了一些东西,这是代码;
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(popoverController != nil)
{
[popoverController release];
popoverController = nil;
}
UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:picker];
popoverController = popover;
popoverController.delegate = self;
[popover presentPopoverFromRect:CGRectMake(0, 0, 200, 800)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
else
{
[self presentModalViewController:picker animated:YES];
}
// [self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error accessing photo library"
message:@"Device does not support a photo library"
delegate:nil
cancelButtonTitle:@"Abort!"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
if (buttonIndex == 1) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType =UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error accessing Camera"
message:@"Device does not support a Camera"
delegate:nil
cancelButtonTitle:@"Abort!"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSLog(@"the info opf picker is %@",info);
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];
NSData *imageData;
if ([info objectForKey:UIImagePickerControllerEditedImage]) {
UIImage *image2=[info objectForKey:UIImagePickerControllerEditedImage];
//UIImage *myscaledImage=[self scaleImage:image2 toSize:CGSizeMake(18, 24)];
//imageData = UIImagePNGRepresentation(myscaledImage);
imageData=UIImageJPEGRepresentation(image2, .4);
NSLog(@"the lenght of the edited image data is %d",[imageData length]);
}
else {
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
//UIImage *myscaledImage=[self scaleImage:image toSize:CGSizeMake(18, 24)];
//imageData = UIImagePNGRepresentation(myscaledImage);
imageData=UIImageJPEGRepresentation(image, .6);
NSLog(@"the lenght of the image dataa is %d",[imageData length]);
}
NSDictionary *tempDict=[NSDictionary dictionaryWithObjectsAndKeys:imageData,@"Image",@"Theme",@"Cell_Text",nil];
// NSLog(@"the custom array%@ and the row =%d", customArray,currentCameraRow);
[customArray replaceObjectAtIndex:currentCameraRow withObject:tempDict];
[pool drain];
//NSLog(@"")
[self startThread];
[picker dismissModalViewControllerAnimated:YES];
[myCustomTableView reloadData];
NSLog(@"size of myObject: %zd", malloc_size(myCustomTableView));
}
-(UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)newSize {
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissModalViewControllerAnimated:YES];
}发布于 2012-12-08 02:08:45
错误非常明显:
iPad上的
,UIImagePickerController必须通过UIPopoverController
在iPad上运行时,需要将图像拾取器放在弹出控制器中。当sourceType用于图片库时,这是正确的。基于相机的图像拾取器可以显示为全屏模式视图控制器。
这在iPhone上不是问题,因为iPhone不支持UIPopoverController。
示例应用程序PrintPhoto演示了如何在弹出窗口中显示图像选择器。具体来说,请参阅PrintPhotoViewController.m。
发布于 2012-12-08 02:19:07
这样做:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//present as a pop over vc
} else {
//present as a modal vc
}要显示弹出窗口,可以使用此方法
- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated您可以在此链接link上阅读文档
https://stackoverflow.com/questions/13768547
复制相似问题