ios - UIImagepicker works for camera but not for photo album -
i have following code let user take photo or select album. while taking picture camera works perfect, when choose button triggers action choose album album comes cant select photo. warning in console when launching choose album method not when launch take camera method. below relvant code , warning.
.h
@interface sitespectakephoto : uiviewcontroller <uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate> @property (strong, nonatomic) nsstring *pbvlocname; @property (strong, nonatomic) iboutlet uitextfield *desctextfield; @property (strong, nonatomic) iboutlet uiimageview *imagefield; @property (strong, nonatomic) uiimagepickercontroller *imagepicker; @property (nonatomic, strong) iboutlet uilabel *successlabel; @property uiimage *imagetosend; @property nsstring *desc; - (ibaction)imagefromcamera:(id)sender; - (ibaction)resignkeyboard:(id)sender; -(ibaction)uploadbuttonclicked:(id)sender; @end
.m
- (ibaction)imagefromcamera:(id)sender { imagepicker = [[uiimagepickercontroller alloc] init]; imagepicker.delegate = self; imagepicker.sourcetype = uiimagepickercontrollersourcetypecamera; imagepicker.cameradevice = uiimagepickercontrollercameradevicerear; [self presentviewcontroller:imagepicker animated:yes completion:nil]; } - (ibaction)imagefromalbum:(id)sender { imagepicker = [[uiimagepickercontroller alloc] init]; imagepicker.delegate = self; imagepicker.sourcetype = uiimagepickercontrollersourcetypesavedphotosalbum; [self presentviewcontroller:imagepicker animated:yes completion:nil]; } #pragma mark - image picker delegate methods // dismiss image picker on selection , use resulting image in our imageview - (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingimage: (uiimage *)image editinginfo:(nsdictionary *)editinginfo { [[imagepicker presentingviewcontroller] dismissviewcontrolleranimated:yes completion:nil]; [imagefield setimage:image]; imagetosend = image; } // on cancel, dismiss picker controller - (void)imagepickercontrollerdidcancel:(uiimagepickercontroller *)picker { [[imagepicker presentingviewcontroller] dismissviewcontrolleranimated:yes completion:nil]; } - (ibaction)resignkeyboard:(id)sender { desc = desctextfield.text; [sender resignfirstresponder]; }
and warning when press button fire imagefromalbum method:
warning: attempt present <uiimagepickercontroller: 0x1d59d6b0> on <uinavigationcontroller: 0x1e0319f0> while presentation in progress!
again, album shown nothing happens when tap image or press cancel button, seems me method not recognizing uiimagepicker delegate methods whereas imagefromcamera method is. in advance help!
the key phrase in error message "while presentation in progress". suggests doing @ time when presentviewcontroller
firing. bet you've accidentally hooked button two methods trying execute 2 presentviewcontroller
commands simultaneously. use connections inspector @ right of interface builder straighten out.
Comments
Post a Comment