ios - How to implement UIAlertcontroller as PopOver(with arrow direction up) in a UIBarbutton -


i know old school question - did searched web , found solutions deprecated. how implement uialertcontroller popover(with arrow direction up) in barbutton. here's code:

 - (ibaction)eventsortingaction:(uibarbuttonitem *)sender {  uialertcontroller * view=   [uialertcontroller                          alertcontrollerwithtitle:@"my title"                          message:@"select choice"                          preferredstyle:uialertcontrollerstyleactionsheet];  uialertaction* ok = [uialertaction                  actionwithtitle:@"ok"                  style:uialertactionstyledefault                  handler:^(uialertaction * action) {                      //do thing here                      [view dismissviewcontrolleranimated:yes completion:nil];                   }]; uialertaction* cancel = [uialertaction                      actionwithtitle:@"cancel"                      style:uialertactionstylecancel                      handler:^(uialertaction * action) {                          [view dismissviewcontrolleranimated:yes completion:nil];                       }]; [view addaction:ok]; [view addaction:cancel]; [view setmodalpresentationstyle:uimodalpresentationpopover]; view.modalinpopover = yes; view.popoverpresentationcontroller.permittedarrowdirections = uipopoverarrowdirectionup; view.popoverpresentationcontroller.delegate = self; [self presentviewcontroller:view animated:yes completion:nil];  uiview* senderview = [sender valueforkey:@"view"]; //hack uipopoverpresentationcontroller* popover = view.popoverpresentationcontroller; if (popover) {    popover.sourceview = senderview;    popover.sourcerect = senderview.bounds;    popover.permittedarrowdirections = uipopoverarrowdirectionup;    popover.barbuttonitem = self.actionbarbutton;    popover.delegate = self; }} 

apparently got "popover = nil". please help! in advance!

by way code not mine, testing in xcode.

uialertcontroller *alertcontroller = [uialertcontroller alertcontrollerwithtitle:nil                                                                          message:nil                                                                   preferredstyle:uialertcontrollerstyleactionsheet];  uialertaction *actncamera = [uialertaction actionwithtitle:@"camera" style:uialertactionstyledefault                                                    handler:^(uialertaction * action) {                                                    }];  uialertaction *actnlibrary = [uialertaction actionwithtitle:@"library" style:uialertactionstyledefault                                                     handler:^(uialertaction * action) {                                                     }];  [alertcontroller addaction:actnlibrary]; [alertcontroller addaction:actncamera]; [alertcontroller setmodalpresentationstyle:uimodalpresentationpopover]; uipopoverpresentationcontroller *poppresenter = [alertcontroller                                                  popoverpresentationcontroller]; poppresenter.sourceview = self.view; cgrect frame = self.navigationcontroller.navigationbar.frame; frame.origin.x = self.navigationitem.leftbarbuttonitem.width; poppresenter.sourcerect = frame; poppresenter.barbuttonitem = self.navigationitem.leftbarbuttonitem; [self presentviewcontroller:alertcontroller animated:yes completion:nil]; 

output

enter image description here


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -