In WWDC 2013 video, Apple suggests displaying picker in place in a table view in iOS 7. How to insert and animate a view between table view cells?
Like this, from the Apple calendar app:
In WWDC 2013 video, Apple suggests displaying picker in place in a table view in iOS 7. How to insert and animate a view between table view cells?
Like this, from the Apple calendar app:
The answer from Aaron Bratcher worked except when used with multiple sections. The animations were a bit choppy and it didn't slide the next sections down very well. To fix this I iterated through the next set of sections and translated the rows down the same amount as the date picker's height.
I edited the didSelectRowAtIndexPath to:
I have taken the DateCell source from Apple, and removed the storyboard file.
If you want one without storyboard, take a look at: https://github.com/ajaygautam/DateCellWithoutStoryboard
Adding to the previous answers and @Aaron Bratcher solution...
I was getting choppy animations since iOS 9, and the table was taking a while to load, and enough to be annoying. I narrowed it do to the date pickers being slow to load from the storyboard. Adding the pickers programmatically rather than in the storyboard improved the loading performance, and as a by-product, the animation is smoother.
Remove the date picker from storyboard and have an empty cell, which you set the height as in previous answers, and then call an initialise on viewDidLoad:
Then implement the action e.g.
This loads the table much faster than previously. You also remove the animation line from
didSelectRowAtIndexPath
as it animates smoothly without it (ymmv).Adding to the previous answers,
I tried both @datinc and @Aaron Bratcher solutions, both worked great but the animation was not so clean in a grouped static tableView.
After playing with it a little bit I got to this code that works clean and great for me -
The main change is to use -
to update the row, this way the rest of the table sections and cells are not animating.
Hope it helps someone.
Shani
Using this answer without the animation works correctly in iOS 8.1. I have converted it into Swift below:
You can use the answer I had previously given below or use this new class in Swift I made to make this task a lot simpler and cleaner: https://github.com/AaronBratcher/TableViewHelper
I find the code provided by Apple to be problematic in a couple of ways:
For static cell tables, I define my date picker cell below my date display cell and have a flag identifying if I'm editing it. If I am, I return a cell height appropriate, otherwise I return a cell height of zero.
When the row showing the date is clicked, I change the flag and do the update animation to show the picker.
If I have multiple date/time pickers in the same table, I set the flags accordingly on the click and reload the appropriate rows. I've found that I can keep my static table, use a lot less code, and it is easier to understand what is happening.