3/04/2010

UIImagePickerController doesn't work in certain cases

The following are the codes that use UIImagePickerController with UIImagePickerControllerSourceTypeCamera.
This code is written in subclass of UIViewController and "self" is UIViewController.

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  UIImagePickerController *controller = [[UIImagePickerController alloc] init];
  controller.sourceType = UIImagePickerControllerSourceTypeCamera;
  [self presentModalViewController:controller animated:NO];
  [controller release];
}

This code doesn't work at -viewDidLoad and -viewWillAppear:
At -viewDidAppear:, that works properly.

For example, in AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  //insert initialize code here, not work
  [window addSubview:viewController.view];
  [window makeKeyAndVisible];
  //insert initialize code here, work

  return YES;
}

初期化した UIImagePickerController を View がオフスクリーン状態の ViewController を利用して表示しようとすると正しく動作しない。UIImagePickerControllerSourceTypePhotoLibrary でも試してみたけど同じく動作しない。View がオンスクリーンになっている ViewController を利用して表示しないといけないみたい。

spec iPhone 3GS OS 3.1.3

No comments:

Post a Comment