Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMichael McKenna
3,451 PointsHow can I retrieve the date from a date picker inside a custom cell? (Swift)
I'm using expandable/collapsible views using the stack view, and when the first row is tapped, two text fields and a date picker appear. Everything else so far has worked except the date picker. It is always only returns today's date, and it doesn't respond to the date changing. Anyway here's the code:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as! CreateEvent1
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action:Selector("datePickerAction:"))
cell.datePicker.addGestureRecognizer(tapGestureRecognizer)
return cell
}
func datePickerAction(sender: AnyObject) {
var dateFormatter = NSDateFormatter()
self.date = sender.date
}
So regardless, self.date always returns today's date and doesn't change.
Michael McKenna
3,451 PointsMy intention is to get the date from the date picker which is located inside the custom cell. Sorry Jhoan I have no idea what other information I need to give you. I posted the relevant code.
Jhoan Arango
14,575 PointsPerhaps you may want to follow this tutorial... Seems like your code may be missing some more set up on the datepicker method.
Michael McKenna
3,451 PointsThat was correct. I was improperly using the tapGestureRecognizer when I should've used the "addTarget" method. Thank you
Jhoan Arango
14,575 PointsJhoan Arango
14,575 PointsPlease help me understand what you are trying to do a bit more..
Flow of the app, what your intention is, etc..
This way i will be able to help you