0

I am trying to implement the imagepickercontroller inside a UITabBarController. So far, so good....

In my ViewController, where I initiate the imagePickerController and then place in my TabBarViewController tabbar array, I implemented the "loadview" method:

- (void)loadView{
    self.arController = [[IFAugmentRealityController alloc] initWithViewController:self];
    [self showCamera];
    [self initOverlayController];
    self.picker.delegate = self;
    [self.view addSubview:self.picker.view];

}

- (void)initOverlayController {
    overlay = [[IFAROverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
    overlay.delegate = self;    
}

- (void)showCamera {
    self.picker = [[UIImagePickerController alloc] init];
    self.picker.navigationBarHidden = YES;
    self.picker.toolbarHidden = YES;
    self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.picker.showsCameraControls = NO;
    self.picker.cameraViewTransform = CGAffineTransformScale(self.picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
    self.picker.cameraOverlayView = overlay;
}

But when I run the app, the app seems to create an inifite loop within the loadView method, and the tabbar does not react anymore. Did I miss something out?

I do not want the ImagePickerController to be fullscreen and pushed with the "presentviewcontroller" method, but loaded as a "normal" view inside one of the tabs.

So my questions are:

1) should I rather use "viewdidload" instead of "loadview"? Because with viewdidload it seems to be working

2) But when using viewdidload I can't fix the frame in which the imagepicker should be shown. There is always a black bar under the video screen and above the tabBar.

Thanks a lot!!

konturgestaltung
  • 467
  • 6
  • 19
  • 1
    I think the infinite loop is coming in when you send the `-addSubview` message to `self.view` before setting the view itself with something like `self.view = [[UIView alloc] initWithFrame:someFrame];` because, technically, while in `loadView` you're supposed to be setting the view controller's view. If `self.view` is `nil` and you try to send it messages, `-loadView` is called again. – Hyperbole Feb 21 '13 at 18:57
  • but isn't the view initialized already in the "showCamera" method, that is loaded in the "loadView" before adding the subview? – konturgestaltung Feb 21 '13 at 18:59
  • Yep!! Now I got it! Just initialized the self.view with an UIView fist... solved my problem perfectly!! Thank you – konturgestaltung Feb 21 '13 at 19:03
  • Great! I'll add my comment as an answer! – Hyperbole Feb 21 '13 at 19:43

1 Answers1

1

I think the infinite loop is coming in when you send the -addSubview message to self.view before setting the view itself with something like self.view = [[UIView alloc] initWithFrame:someFrame]; because, technically, while in loadView you're supposed to be setting the view controller's view.

If self.view is nil and you try to send it messages, -loadView is called again, resulting in the infinite loop.

Hyperbole
  • 3,917
  • 4
  • 35
  • 54