Problem when showing UIImagePickerController

Hi!

I have a problem that is driving me crazy. I’ve been looking the solution for hours and I still can’t find it.

I have a scene (SceneA.cpp) that calls a UIImagePickerController. The way that I do it lies in the following code:

IOSUtilities.h

#ifndef CopyleftPilotIOSUtilities*_
#defineCopyleftPilotIOSUtilities*_

#include
#include “cocos2d.h”

using namespace std;

void iosShowPhotoRoll();

#endif

IOSUtilities.cpp

#include “IOSUtilities.h”
#include “PhotoLibrary.h”

#include <sys/types.h>
#include <sys/sysctl.h>

#define IOS_ENV
//#define ANDROID_ENV

void iosShowPhotoRoll()
{
PhotoLibrary **photos = init];
;
}
**PhotoLibrary.h*

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import “AppController.h”
#import “DelegateHandler.h”

`interface PhotoLibrary : NSObject<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
AppController *appController;
BOOL iOS4;
UIImagePickerController *imagePickerController;
UIImage *choosenPhoto;
}

property (assign) AppController **appController;property (nonatomic, retain) UIImage *choosenPhoto;

-(void)showImagePicker;

`end
**PhotoLibrary.m*

#import “PhotoLibrary.h”

`implementation PhotoLibrary

`synthesize appController, choosenPhoto;

~~init
{
if)
{
NSString *deviceVersion = .systemVersion;
int deviceVersionInt = ;
if
iOS4 = YES;
else
iOS4 = NO;
appController = delegate];
}
return self;
}
~~(void)showImagePicker
{
if(imagePickerController == nil)
{
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;

imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}

if(!iOS4)
[appController.viewController presentViewController:imagePickerController animated:YES completion:nil]; //iOS 6
else
[appController.viewController dismissModalViewControllerAnimated:YES];
}

~~imagePickerController:picker didFinishPickingMediaWithInfo:info
{
if
; //iOS 6
else
;
self.choosenPhoto = ;

;
imagePickerController = nil;

}
~~ (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
{
if(!iOS4)
[appController.viewController dismissViewControllerAnimated:YES completion:nil]; //iOS 6
else
[appController.viewController dismissModalViewControllerAnimated:YES];

[imagePickerController release];
imagePickerController = nil;
self = nil;
}

-(void)dealloc
{
[super dealloc];
}

`end

IOSUtilities works as a bridge between C++ and Objective C. (The file type for the .cpp file is Objective-C++ Source). IOSUtilities calls the UIImagePickerController by creating the PhotoLibrary object and calling the method showImagePicker. Then in my SceneA I call the IOSUtilities method “iosShowPhotoRoll”:

void SceneA::choosePhoto(CCObject *sender)
{
iosShowPhotoRoll();
}

Everything works like a charm. Now, the problem is that I have another scene called SceneB.cpp that has a CCTextFieldTTF. In SceneB, when I touch the CCTextField the keyboard is shown. Also I implemented the keyboardWillHide and keyboardWillShow methods. Each time the keyboard is shown I move the children of the scene in order to not let the textfield behind the keyboard (by doing this, the user will always see what is typing) and when the keyboard will hide, I move the children to their original position.

HERE IS THE PROBLEM:

When I enter to SceneB +WITHOUT CALLING THE PHOTO ROLL IN SCENEA+, everything works fine; the children moves perfectly well when the keyboard is shown and return to their original position when is hidden. BUT, IF I ENTER TO SCENEA, CALL THE PHOTO ROLL, THEN I ENTER TO SCENEB AND CALL THE KEYBOARD the methods keyboardWillShow and keyboardWillHide are called like 9 times and the children does not return to their original position.

I don’t know if this is a problem of the views (the OpenGL view where Cocos2d-x works) when the UIImagePIckerController is called by the appcontroller.

I can’t seem to find the solution, I’m becoming insane.

Thanks in advance and sorry for the long post.

(Sorry about the formatting of the code, it cannot seem to detect the '`’)