ios - UIImagePicker reappears after being image is selected -


i have uiimagepicker keeps reappearing after have selected image. code checking camera , displaying uiimagepicker based on fact there no camera in simulator.

- (void)viewwillappear:(bool)animated {     [super viewwillappear:animated];     self.imagepicker = [[uiimagepickercontroller alloc] init];     self.imagepicker.delegate = self;     self.imagepicker.allowsediting = yes;      if ([uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {         self.imagepicker.sourcetype = uiimagepickercontrollersourcetypecamera;     }     else {         self.imagepicker.sourcetype = uiimagepickercontrollersourcetypephotolibrary;     }     self.imagepicker.mediatypes = [nsarray arraywithobjects:(nsstring *)kuttypeimage, nil];     [self presentviewcontroller:self.imagepicker animated:no completion:nil]; }  - (void)viewwilldisappear:(bool)animated {     [super viewwilldisappear:animated];     [self clear]; }  - (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info {     uiimage *chosenimage = info[uiimagepickercontrollereditedimage];     self.imageview.image = chosenimage;     [self dismissviewcontrolleranimated:yes completion:nil]; } 

do need force reload initial view? there smarter way this?

edit

i added bar button navigation bar , im firing code on action. fixed issue , seems better way this.

probably viewwillappear being called everytime uiimagepickercontroller disappears - because view controller put code becoming visible again.

you can try creating uiimagepickercontroller in viewdidload instead, or use boolean property check if calling first time.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -