I am trying to just set up a UIImagePickerController to take a picture using the Camera and I am having a tough time. Been at all night trying to implement code from tutorials and just not getting it to happen...it's one of those nights. Can anyone please just post the source code for allocating a UIImagePickerController geared for taking pictures programatically (I don't want to use InterfaceBuilder at all). I know somethings, like the delegate that is specified has to implement the proper protocol and the like.
For reference, as I read it might matter, I want to have the UIImagePicker live in a UIView called MainView, which is an instance variable of my RootViewController (which is a UIViewController) which in turn is an instance variable of my Application Delegate. (So it is AppDelegate--->RootViewController--->MainView---->The picker lives here.
I know this is probably a silly thing that everyone can do; but it's just kicking the crap out of me right now and I gotta go to sleep...work tommorow morning.
If it were directly in the view controller, it is simple to display. All you have to do is presentModalViewController: animated:
Here is what I do when I present it in a UIView instead of a UIViewController:
Code:
UIImagePickerController *pc = [[UIImagePickerController alloc] init];
pc.delegate = self;
pc.sourceType = UIImagePickerControllerSourceTypeCamera; //or album
pc.xxxx //a lot of other options you could specify
[self addView:pc.view];
Make sure you end up releasing it in the delegate call backs.
Oh, so my problem was probably that I was trying to implement it in a UIView and not a UIViewController. I already have my application hierarchy the way I want and don't want to change it....I suppose I can just make Mainview a UIViewController instead of a UIView?
Yes that's more or less the code I had in my Mainview, but all it did was show a light blue colored toolbar or some such at the top of the screen. Perhaps it just simply has to be in a UIViewController and not a UIView... i noticed that I got a warning that the UINavigationControllerDelegate Protocol needed to be implemented, in addition to the UIImagePickerControllerDelegate Protocol, which I thought strange (probably because it wasn't a UIViewController which I guess has the nav protocol built in).
You still have to implement that delegate. The UIImagePickerController inherits from the navigation controller. That is why you are required to implement that delegate as well. All you have to do is add it to your header file, then the warning disappears. You actually dont have to put any code in to work with the nav controller delegate.
It is exactly what you posted above. I just have UIView called Mainview (that is getting displayed just fine) where the only thing I want it do is get this camera thing going.
This class implements the proper delegates and there are no errors or warning. I think I have all frameworks necessary. I didn't write the code for the delegate functions because I was just testing...maybe thats my problem. What am I missing? I wish the damn apple docs would always come equipped with a full implementation example code.....
Could you do me a favor and just post the .m file code for a UIView that all it does is this lol! Thanks...
Thanks for that; so, since it is using present modal view I have to make MainView a UIViewController correct? Tkilmer, do you recommend this approach as well, or do you think another approach is more suited to my scenario? Thanks all!
Arg...Now I am just getting a blank screen. I have verified through breakpoints that the call to create the picker and display it gets executed (and also that the call to dismiss it is NOT called)...I don't know what I am doing wrong? I literally just changed the UIView to a UIViewController and made the minor tweaks necessary (self.view here and there instead of self) and copied the code above.... When I transition to this view the app seems to think for a second; but then only a black screen is shown (or if i put a toolbar in MainView.view for example that will show up; so the view is displaying fine; just no camera). There are no errors or warnings; and I am trying it on the Device itself, not just the Sim.
UIImagePickerController is designed to run as a model view controller. It shouldn't be pushed. I know it is OK to push in SDK 2.0 but that won't work in 2.2.
Do the PresentModalController from your main controller and it will work fine.
I actually tried that; I got rid of the mainView alltogether and tried to implement it in my RootViewController UIViewController object; no dice. I think I'm just at that point where I'm just cursed and nothing I can do can work.
If anyone can just simply send me a working xcode project that just has a RootViewController pulling up the camera in its viewDidLoad method I'd be much appreciative. Basically just the simplest sample app that fires up the camera. At this point I just need to look at the simplest thing that actually works and build up from there.
I actually tried that; I got rid of the mainView alltogether and tried to implement it in my RootViewController UIViewController object; no dice. I think I'm just at that point where I'm just cursed and nothing I can do can work.
Did you use presentModalController, or did you add the view to your view?
I would suggest you to create a blank project, and make it work in the blank project first. Maybe something else in your project is conflicting with it.
I would suggest you to create a blank project, and make it work in the blank project first. Maybe something else in your project is conflicting with it.
I used present; in a blank new project. Like I said; I'm at that point where I am just cursed; no errors, no warnings and everything looks right. Just...nothing.
I'm not trying to be crafty and get other people to do the work for me; I've been at this for two days and its making me go batty; it wold be simple if the docs were just like: here's this class and here is a sample of how its implemented. Even in research assistant it says Example Code: 0.
Also I don't think its terrible just asking for someone to send me this sample project in it with nothing but this; it's not proprietary code or anything and its something that should be in a apple sample app anyway....arg, I got to go to sleep; another night completely wasted with no information gained...that's just the worst thing ever.
I don't even need anything nonstandard like that. I'm just looking for the normal implementation of this working; I don't know why its not working for me. I'm literally just making a new project, making a UIViewController object that has the above camera implementation code. No errors; I can verify that the view of the UIViewController is being displayed; and I can verify via breakpoints that the code to present the modal view is being executed....nothing happens and I don't know why. I got the right framworks; the ViewController implements the right delegates etc...ugh.
That's why I am just basically begging anyone to just send me an xcode project with what I am stating above; it should literally take about 2 minutes to create from scratch.