ios - Make UIDatePicker appear with the time when a static UITableViewCell is tapped -
i have app want, tapping static uitableviewcell within uitableviewcontroller, uidatepicker to pop on bottom of screen, lets me pick time(e.g. hour, minute, , am/pm).
obviously, have created programmatically because
i want hide it(when button on picker pressed or somewhere outside picker tapped)
i can't add view controller. ideas?
apple implements similar functionality in datecell example, * islam q.* mentioned in comment on original question. however, answer, i'll assume you'd rather described.
your goal can achieved little code.
- first, drag
uidatepickerout onto view controller in storyboard. then, connect date picker
iboutletin the
implementation of view controller subclass.@iboutlet weak var datepicker: uidatepicker!in same view controller's
viewdidload()(orviewdidappear(:), if that's more appropriate), move date picker below bottom edge of screen changing frame. don't animate frame change. nothing's onscreen anyway.override func viewdidload() { super.viewdidload() self.datepicker.frame = self.offscreenframe // ... }next, in
tableview(_:didselectrowatindexpath:), animatedatepickeronto screen. right before perform animation, make sure set date picker's date current date.self.datepicker.date = uidate() // animationfinally, make sure animate dismissal of date picker when appropriate (in
tableview(_:diddeselectrowatindexpath:), example).uiview.animatewithduration(0.2) { () -> void in self.datepicker.frame = self.onscreenframe }
note actual implementation of each of these bullet points can differ depending on situation. also, offscreenframe , onscreenframe "imaginary" variables used simplify code snippets.
Comments
Post a Comment