Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RenoRosco

macrumors newbie
Original poster
May 26, 2010
1
0
Hi everyone,

I am relative new to X-Code programming and encounter a strange problem with my current Project that is for iPad only. I Use the Unity engine and use X-Code only if i need some functions that Unity doesn´t offer so be patient with my X-Code skills.

I want to show the picture Gallerie of the iPad and let the user choose some images for use in my Game.

I already used the UIImagePicker on the iPhone and wanted to reuse the code. But on the iPad the gallerie has to be shown in the UIPopoverController. I implemented the code but now the app gets terminated after the user selects about 4-10 images.
I think there has to be some memoryleak but i cant find it.

If the User cancels the gallerie he can open it 1000 times so i think the problem has to be in the didFinishPickingMediaWithInfo-function. I cleaned the code out so it just opens the ImageGallerie and i do nothing else the return to Unity if the user choose a picture but the problem is still there.

I would be very happy if some of you that are familar with X-Code can take a look at my code and hopefully tell me what is wrong.

Thx
Reno

Here is the cleaned out code code

Code:
- (void)photoPickerAdv {
   UnityPause(YES);

   w = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
   vc = [[UIViewController alloc] init];
   [w addSubview: vc.view];
   [w makeKeyAndVisible];
   
   if(self.popoverController == nil)
   {   

      UIImagePickerController* picker = [[UIImagePickerController alloc] init];
      picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
      picker.delegate = self;
      picker.allowsEditing = YES;
      picker.wantsFullScreenLayout = YES;

      self.popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];;     

      [picker release];
      [popover release];
      popoverController.delegate = self;
   }

   [self.popoverController setPopoverContentSize:CGSizeMake(160,160) animated:YES];
   CGRect selectedRect = CGRectMake(0,0,1,1);
   [self.popoverController presentPopoverFromRect:selectedRect inView:vc.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
   [vc release];



- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
   [self sendUnityResultString:@"cancel"];
   [w resignKeyWindow];
   [w release];

   UnityPause(NO);
}



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   [self.popoverController dismissPopoverAnimated:true];

   [[picker parentViewController] dismissModalViewControllerAnimated:YES];
   [w resignKeyWindow];
   [w release];
   
   [self sendUnityResultString:@"cancel"];
   UnityPause(NO);
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
   NSString *s = @"cancel";
   [self sendUnityResultString:s];
   
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
   [w resignKeyWindow];
   [w release];

   UnityPause(NO);
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.