takePicture is being difficult on 3.1
Ok. So I have a ViewController which implements the UIImagePickerControllerDelegate. Great. I also have an overlay view going on top of my picker. I have a button on said overlay that I want to call takePicture on.
My question is, How is this done? takePicture isn't something I need to write myself is it? It's defined in UIImagePickerController right?
The picker modally pops up fine, i can see an image through the camera, but when I go to push the button to take the picture, I have a problem.
I have this 开发者_C百科code set up on the button:
[button addTarget:self action:@selector(takePicture) forControlEvents:UIControlEventTouchUpInside];
With the above, I usually get an NSException error, but when I call takePicture from a separate method, it simply doesn't fire.
As part of this, should my picker delegate be set to the overlay or the viewcontroller that presents the picker?
Also, should my overlay AND my view controller implement the picker delegate in the header?
Thanks in advance.
The takePicture
method is on the UIImagePickerController
object. Right now, your button is calling takePicture
on the overlay's view controller, I think. (I can't tell for sure because you didn't post which method that line of code is in.)
so it should be
[button addTarget:picker action:@selector(takePicture) forControlEvents:UIControlEventTouchUpInside];
Obviously to make this work the code needs to have the picker variable set to point to the UIImagePickerController
; the usual way to do this would be to store a pointer to the main view controller and/or the image picker itself in your application delegate.
Only one class needs to implement the image picker delegate; you can decide which one you want it to be.
精彩评论