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

  1. i want hide it(when button on picker pressed or somewhere outside picker tapped)

  2. 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 uidatepicker out onto view controller in storyboard.
  • then, connect date picker iboutlet in the
    implementation of view controller subclass.

    @iboutlet weak var datepicker: uidatepicker! 
  • in same view controller's viewdidload() (or viewdidappear(:), 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:), animate datepicker onto screen. right before perform animation, make sure set date picker's date current date.

    self.datepicker.date = uidate() // animation 
  • finally, 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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -