objective c - iPad crashes when showing photos or taking photo--nil source view -


the follow code crashes when run on ipad error message:

(<uipopoverpresentationcontroller: 0x1377a19e0>) should have non-nil sourceview or barbuttonitem set before presentation occurs.'

however, in code have following, , checked breakpoints , console prinouts ensure sourceview , barbutton not nil. need avoid this? error appears on ipad. here method causes trouble:

- (void)showchooseimageoptions { uialertcontroller *alertcontroller = [uialertcontroller alertcontrollerwithtitle:nil message:nil preferredstyle:uialertcontrollerstyleactionsheet]; uialertaction *chooseaction = [uialertaction actionwithtitle:@"choose photos" style:uialertactionstyledestructive handler:^(uialertaction *action) {     [self showlibrary];   }]; uialertaction *takeaction = [uialertaction actionwithtitle:@"take photo" style:uialertactionstyledestructive handler:^(uialertaction *action) {     [self showcamera];  }]; self.directionstextview.text=@""; [alertcontroller addaction:chooseaction]; [alertcontroller addaction:takeaction]; uialertaction *cancelaction = [uialertaction actionwithtitle:@"cancel" style:uialertactionstylecancel handler:^(uialertaction *action) {        if (self.imageview.image)   {         self.directionstextview.text=@"tap circle change image";     } else{         self.directionstextview.text=@"tap blue circle choose or take image";       }  }];   [alertcontroller addaction:cancelaction]; alertcontroller.view.tintcolor=[colorsuperclass returnapplicationmaincolor];           alertcontroller.popoverpresentationcontroller.barbuttonitem = self.navigationitem.rightbarbuttonitem;   if ( [alertcontroller respondstoselector:@selector(popoverpresentationcontroller)] ) {      // @ least ios8      alertcontroller.popoverpresentationcontroller.sourceview = self.view;   }  [self presentviewcontroller:alertcontroller animated:yes completion:nil]; } 

and method showcamera , showlibrary nothing but:

-(void)showcamera   { if (target_iphone_simulator)    {     //do nothing, simulator cannot handle pressing take photos... } else{     [self showimagepickerforsourcetype:uiimagepickercontrollersourcetypecamera]; } }  - (void)showlibrary { [self showimagepickerforsourcetype:uiimagepickercontrollersourcetypephotolibrary]; } 

and show source type method:

- (void)showimagepickerforsourcetype:(uiimagepickercontrollersourcetype)sourcetype { uiimagepickercontroller *imagepickercontroller = [[uiimagepickercontroller alloc] init]; imagepickercontroller.modalpresentationstyle = uimodalpresentationpopover; //this line important, because otherwise, tab bar go out of scope (a consequence of using modal segues , tab controllers!) imagepickercontroller.sourcetype = sourcetype; imagepickercontroller.delegate = self; imagepickercontroller.allowsediting = yes; [self presentviewcontroller:imagepickercontroller animated:yes completion:nil]; } 


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -