Modern Era UITableView Animation - ios

In a UITableView what would be the most convenient way of showing up additional information from a smooth scrolling effect?
You might want to look at the screenshot below. The top UITableViewCell is a kind of "Create new stuff"-button field, and I would like a formular to show up from below this field with a smooth uniform scroll animation.
How is this best achieved? Do I want to create a view and manipulate with the current cell's height and animate+display a SubView or do I want to manipulate with the Delegate and DataSource to simply create a condition on showing more cells if the button is pressed (which causes a reloadData with some kind of animation set true) ?
I could wander around in the wilderness and mess around, but I guess that I'm not the first one to encounter such issue and that someone might have some constructive input.
** UPDATE **
All the interesting stuff happens in indexPath.section = 0 so I now simply created an (atomic) BOOL createFormActive and manipulate cell data accordingly with my didSelectRowAtIndexPath looking something like this:
if (indexPath.section == 0) {
self.createFormActive = !self.createFormActive;
[tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
}
This works pretty well. So you could say I have found a solution, but feel free to use this thread as inspiration or discussion.

I've had good results with the "showing more cells if the button is pressed" approach. Relying on the table view's built-in animations is good bang for the buck IMO. Initially, however, I found managing a dynamic data model and calculating the batch updates can get out of hand quickly.
I ended up writing the TLIndexPathTools framework to make these things easy. Take a look at the Settings example project, a "settings" table view that morphs into a couple of different configurations as you make selections. I've done a much more elaborate real-world settings screen with table animation and it turned out very well.

Related

How to add cell to tableview's reuse queue before 'cellForRow:'?

Creating a cell costs a lot of time and make the first scroll lagging, so I want to create a cell and add it to tableview's reuse queue before cellForRow: called.
I use dequeueReusableCellWithIdentifier: in viewDidLoad, but when I scroll the table, the cell is being created again.
In general all drawing methods of scrollview should be kept as simple as possible to avoid lag. This means you should prepare your data/model in viewDidLoad/viewWillAppear or even in previous ViewController. Your cellForRow should be as simple as set this image(s) and those text(s) - no checks, no expensive operations such as bluring, retrieving data from CoreData/Network, etc.
If you are not sure which thing exactly causes your lag, you should learn how to use TimeProfiler. If you feel lost in documentation, have a look this(quite outdated though) tutorial.
With thus said I cannot be able to help you anymore until you post some code which we could discuss.

Scrolling rows effects in iOS 7

I want to make scrolling effect in iOS 7 when scroll up, those rows will move like this gif shows. Please forget the effect when scroll down (because I cannot find a better sample). However, I don't know how to do that although did research, any solutions and open sources are appreciated!
http://d13yacurqjgara.cloudfront.net/users/107759/screenshots/1176252/moments-ios7.gif
This is done by adding Gravity effect to UIKit components. Once you add attachmentBehaviors, you can easily achieve this effect.
You can find a tutorial help here.
There is another solution specific to UITableViewCells here.
It is advisable to use a UITableView & on reload table view data animation can be used by the following way to give a bouncing effect during table reload.
[_tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
Corresponding row animation effect should be given here.
For delay in scroll for each section as seen in the gif, I would suggest you to go ahead with animation for individual cells.
Go through this open source link, this might be useful.
Shall try and get back, in-case I perform the exact animation effect.

UITableview cell reinitializing every time in iOS 7

All,
I hope most of you know that with ios7 there is not need to do a null check for tableview reuse
if (cell == nil) {
But unfortunately, because of that the cells are always reinitialized, as we put the code in the same method for initializing values. The problem is only with text fields inside the tableview though.
Let me explain the scenario. I have a table view with multiple rows, and some rows contain multiple text boxes. I populate the textboxes with data from server when the page is loaded. Since the cells are always re-initialized as i explained above, whatever I enter in the field goes away and the server data is re populated once i scroll down and come back to the initial stage. This is because the populating the data code is also in the same place. After fetching a reusable cell it populates the data.
Previously till ios6, we used if(cell==nil) and hence we loaded server data inside the cell and when reusing the cell, this piece of code will never be called.
I have other dirty solutions, but would like to know if someone else has a graceful way of dealing this. Please help.
You just don't store any data in the table view cell but in the model that fills the table cell. This is always the way it should be done.
Looking from the MVC standpoint than the UITableViewCell is a view. Since it is reused by iOS you should use a model to the view.
Yes, this is the expected behavior of UITableView. For performance reasons, cells are reused. Thus, it is your responsibility to populate the views in a Table View Cell every time tableView:cellForRowAtIndexPath: is called.
The thing I don't understand from your question - are you making a network call every single time a cell comes into view? If so, cache the results somewhere. Or, if it's a small amount of data, consider just doing it all in one shot at the beginning (still need to be asynchronous though).
One thing I see a lot of developers do is move a lot of code into UITableViewCell subclasses, which sounds like a good idea because it's modular, but makes solutions for problems like this more difficult. Have the Table View Data Source manage the network calls.
If you need some inspiration, look at Apple's LazyTableImages sample.

Can I find out when a cell is queued?

I have a couple of things in my custom UITableViewCell's that I'd like to clean up before the cell gets queued. In a normal view, I'd put these kinds of calls in -(void)dealloc, but as they're being re-used rather than having an instance each, they won't dealloc. For now, I'd just like to print out a text in the log, NSLog(#"Cell out"); when the cell is queued, or "done".
I'm really just looking for something like -(void)didQueue in the cell-class, but my searches haven't shown anything.
I just found -(void)prepareForReuse, but I need more like prepareForQueue. I have to know when it's on its way out, not back in.
Random thought..: Searching for when the cell leaves the screen (or a bit after) might do exactly the same as what I'm looking for, but I'm thinking that costs a lot of processing..
For iOS 6+ the table view delegate will receive tableView:didEndDisplayingCell:forRowAtIndexPath: which tells you when the cell is not being used any more (irrelevant of queueing).
That said, prepareForReuse would generally be considered the correct place for the code you describe. If it isn't then you are probably assigning the cell responsibility it shouldn't have.

iOS, how to split UITableView into two

I want to split UITableView into two parts, top part and bottom part when I tap somewhere.
the hidden part will open with animation. could anybody please tell me how to do that?
This effect just like at iOS app groups at desktop.
I think "how to split anyview into two parts" is what i want.
My fitst thought is that write code to take a shot of current screen as an image, and disabled the top and the bottom parts. then move down the bottom part.
I don't konw is there an API to do that quickly? or there already exists a repo on Github.
here is a sample image http://oi40.tinypic.com/2hhdw5y.jpg
Make the 'hidden part' a regular table view cell.
In heightForRowAtIndexPath, return the normal cell height for every cell, except for the hidden one. For this one, you will want to return either 0.0 (hidden) or some other value, when it is visible. You can store whether it's expanded or not in a bool property.
When it should expand, update the expanded property and call both
[tableView beginUpdates]; and
[tableView endUpdates];
This will show your previously hidden cell with a nice animation. You can also use this mechanism to hide it again.
You can use expandable tableview and design the tableview according to your needs.
https://github.com/OliverLetterer/UIExpandableTableView

Resources