UIImagePickerController is not in the window heirarchy

1,295 views
Skip to first unread message

Dan Brooking

unread,
Feb 27, 2013, 8:26:36 AM2/27/13
to rubym...@googlegroups.com
Like all my problems that I end up solving, I'm guessing that this is something really simple that I'm missing.  I feel it's an iOS concept I might not be grasping.... anyways...

I am trying to add a UIImagePickerController to a UITabBarController. Basically, when the user selects one of the tab bar items, the camera will be displayed.

All the code I've seen for RubyMotion and UIImagePickerController involves NavigationControllers. Code is basically:

app_delegate.rb:
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(RootController.alloc.init)

root_controller.rb
....stuff....
controller = UIImagePickerController.alloc.init
....more stuff...
self.navigationController.presentModalViewController(controller, animated:true)

So I try the same basic thing with my class for the view controller associated with that tab bar item.  Obviously, I'd need to change navigationController, so I try tabBarController.  I then get a message about presentModalViewController not being a method for tab bar controllers.  I have googled and saw someone suggest using parentViewController - this cause my app to no longer crash but it doesn't work and I get the message about

Warning: Attempt to present <UIImagePickerController: 0x20818ba0> on <UITabBarController: 0x20918ea0> whose view is not in the window hierarchy!

Any help? Thanks
Dan

Colin Thomas Arnold Gray

unread,
Feb 27, 2013, 9:59:18 AM2/27/13
to rubym...@googlegroups.com
You want the image picker to appear in a tab? Then `presentModal` is the wrong tree to bark up. :-)

The navigation controller is all about adding and removing controllers, but with a tab-bar controller, you usually set the controllers once.

    ctlr = UITabBarController.new
    ctlr.viewControllers = [UIImagePickerController.new] # and others...

Also, you should test your image picker by assigning it as the rootViewController, just as a sanity check. 

#colinta
--
 
---
You received this message because you are subscribed to the Google Groups "RubyMotion - Ruby for iOS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubymotion+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dan Brooking

unread,
Feb 27, 2013, 10:32:58 AM2/27/13
to rubym...@googlegroups.com
Ohhhh.. I gotcha. 

So right now, when I set up my tabs, I'm setting them all to classes that are subclassed from UIViewController.  I just want to take that one for the camera and subclass UIImagePickerController?

Colin T.A. Gray

unread,
Feb 27, 2013, 11:03:29 AM2/27/13
to rubym...@googlegroups.com
That's right!

It's also common to put a UINavigationController *within* a UITabBarController, so if that's useful to you, don't shy away from that.  The opposite, though (putting a UITabBarController inside a UINavigationController) is not allowed.

Dan Brooking

unread,
Feb 27, 2013, 4:51:48 PM2/27/13
to rubym...@googlegroups.com
OK, I made that switch and it is working now.  It just isn't working the way I expected.  

To give a little more detail, I'm looking at an iOS project coded in ObjC in XCode and trying to port it over to RubyMotion just as an exercise.

In Xcode, I have:

@interface MainTabBarController : UITabBarController<UIActionSheetDelegate>

and this has 5 views coming off of it.  One of them is:

@interface CameraViewController : UIViewController <UIImagePickerControllerDelegate>

which has this:


-(void)takePhoto {

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

#if TARGET_IPHONE_SIMULATOR

    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

#else

    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

#endif

    imagePickerController.editing = YES;

    imagePickerController.delegate = (id)self;

    

    [self presentModalViewController:imagePickerController animated:YES];

}


In the obj-c version, when someone taps the camera tab, the camera comes up full screen.  When I just add UIImagePickerController as one of the tabs, the tab bar at the bottom stays and the camera takes up the rest of the screen.

Does that make sense?

Colin T.A. Gray

unread,
Feb 27, 2013, 7:14:34 PM2/27/13
to rubym...@googlegroups.com
Aw, shoot, I forgot how annoying it is to hide the tab bar.

Hmm... geez, I dunno.  It seems wrong, to me, to use `presentModal`, but maybe that's the best way to do this! :-/

If you google around for "hide UITabBarController tabBar" you'll get some hits, but it looks like a tricky problem...

Dan Brooking

unread,
Feb 27, 2013, 8:47:03 PM2/27/13
to rubym...@googlegroups.com
OK thanks I'll give that a try!
Reply all
Reply to author
Forward
0 new messages