ios - Adding UIBarButtonItem to UIActionSheet navigation bar (UIDatePicker) -
i created uiactionsheet , added uipickerview on top of it. now, want add 2 button on right , left of uiactionsheet navigation bar title. how can that?
this did far:
- (ibaction)userdidclickedonselectdate:(id)sender { uiactionsheet *actionsheet = [[uiactionsheet alloc] initwithtitle:@"select birthday date:" delegate:self cancelbuttontitle:@"cancel" destructivebuttontitle:nil otherbuttontitles:@"select", nil]; [actionsheet showinview:self.view]; [actionsheet setframe:cgrectmake(0, 100, 570, 383)]; }
i'm trying add uibutton in way, can't figure out why can't see on view. when check uiactionsheet subviews, there (maybe somewhere under).
- (void)willpresentactionsheet:(uiactionsheet *)actionsheet { uidatepicker *pickerview = [[uidatepicker alloc] initwithframe:cgrectmake(10, 50, 50, 216)]; // configure picker... [pickerview setdatepickermode:uidatepickermodedate]; [pickerview settag:action_sheet_picker_tag]; // add picker action sheet [actionsheet addsubview:pickerview]; // add button action sheet uibutton *buttoncancel = [uibutton buttonwithtype:uibuttontypesystem]; [buttoncancel setframe:cgrectmake(5, 100, 200, 200)]; [buttoncancel settitle:@"close" forstate:uicontrolstatenormal]; [buttoncancel setbackgroundcolor:[uicolor redcolor]]; [actionsheet addsubview:buttoncancel]; // gets array af of subviews of our actionsheet nsarray *subviews = [actionsheet subviews]; (id button in subviews) { if ([button iskindofclass:[uibutton class]]) { [button setuserinteractionenabled:no]; [button sethidden:yes]; } } }
this how looks like:
i figure out of there way reach uiactionsheet navigation bar or toolbar (where title located) , add button on top.
thanks in advance.
according people answer's i've managed create better picker view presented same, handles , build way better. i've created uiviewcontroller , added uidatepicker , uitoolbar buttons on top. called that:
- (ibaction)userdidclickedonselectdate:(id)sender { customdatepicker *custompicker = [[customdatepicker alloc] initwithnibname:@"customdatepicker" bundle:nil]; custompicker.delegate = self; custompicker.view.backgroundcolor = [uicolor clearcolor]; self.modalpresentationstyle = uimodalpresentationcustom; [self presentviewcontroller:custompicker animated:yes completion:nil]; }
i alsvo created delegate tells me when cancel , done buttons clicked:
- (void)datepickerdidcancelled:(customdatepicker *)picker { [self dismissviewcontrolleranimated:yes completion:nil]; } - (void)datepicker:(customdatepicker *)picker datedidselected:(nsdate *)date { nslog(@"selecteddate: %@", date); [self dismissviewcontrolleranimated:yes completion:nil]; }
per documentation, shouldn't add subviews uiactionsheets.
uiactionsheet not designed subclassed, nor should add views hierarchy. if need present sheet more customization provided uiactionsheet api, can create own , present modally presentviewcontroller:animated:completion:.
Comments
Post a Comment