Follow up to DatePicker Question
Follow up to DatePicker Question
- Subject: Follow up to DatePicker Question
- From: David Grant <email@hidden>
- Date: Wed, 20 May 2015 12:07:57 -0700
So I found that what I really really wanted was not a popover controller but an inputView.
When I test this in an iPhone 6 it seems to work just fine, but on testing an iPhone 5 the reaction to the date change is kind of slow.
Also, this seems like a lot of code to make this work, so I’m submitting it here because a) it does work, and b) I’m hoping to get some feedback and maybe clean it up or make it run even faster so their is no delay on the iPhone 5.
@IBOutlet weak var dateInput: UITextField!
@IBOutlet var inputDatePicker: UIDatePicker!
func getDate()
{
let transactionDate = NSDate()
let formatter = NSDateFormatter()
formatter.dateStyle = .LongStyle
var datePicker = UIDatePicker()
datePicker.datePickerMode = UIDatePickerMode.Date
dateInput.inputView = datePicker
datePicker.addTarget(self, action: "updateDate:", forControlEvents: UIControlEvents.ValueChanged)
self.dateInput.text = formatter.stringFromDate(transactionDate)
}
func updateDate(sender: UIDatePicker) {
var chosenDate = sender.date
let formatter = NSDateFormatter()
formatter.dateStyle = .LongStyle
self.dateInput.text = formatter.stringFromDate(chosenDate)
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden