How to Insert/Remove/Update UITableView without it appearing to move? - cocoa-touch

After reading this, I'm interested in being able to dynamically update a UITableView without the view scrolling. That is, if the 12th row is visible, and some background process runs and calls for a new row to be inserted at position 0, how can that be done without the table appearing to scroll?
The closest I've been able to come to achieving this is to do any and all updates in a single -beginUpdates/-endUpdates block and to adjust the contentOffset as appropriate after that. But some of my code might have a bunch of calls to -insertRowsAtIndexPaths:withRowAnimation called outside such a block, and when I do that, the thing can scroll all over the place.
How can I make UITableView stand still?

Related

Select CollectionViewCell when scrolled into view

I have a collection view that is 100 points wide with a number of cells that are each also 100 points wide. I've got it setup to support scrolling and paging horizontally so the user can flick left and right and each cell occupies the entire collection view frame.
Originally, I had no scrolling and the user would tap each cell to activate something in the app. Now that its a narrow frame where only one cell can be seen at a time I feel that tapping is redundant and the cell should simply be tapped in effect when it comes in view.
Is there a way to trigger an event such as didSelectItemAtIndexPath when a given UICollectionViewCell becomes the one displayed within my collection view's frame?
UICollectionView responds to selectItemAtIndexPath:animated:scrollPosition:.
It also responds to indexPathsForVisibleItems which will be useful to determine where to make the selection.
You also need to decide when to make the selection, probably best after receiving scrollViewDidEndDecelerating: which the delegate inherits from UIScrollViewDelegate).
But it may be even better advice to look at what your code does upon selection and just do that (launched from the same place in code, probably when scrolling is finished), leaving selection out of it.

Content offset while Inserting item in UICollectionView?

I'm using performBatchUpdates: to insert a new section to my collection view. This comes with the default fade in animation that I'd like to keep. The item I'm inserting is always the last item, so I'd like to offset my collection view to the bottom to make it visible.
Right now I'm able to achieve this by using scrollRectToVisible: in the completion callback of the batch update method. However, by the time it scrolls, the fade in animation already happened out of frame.
I'd like for both to happen simultaneously. Is this possible?
One approach I've tried is pre-calculating the new size manually ahead of the updates and scrolling first, but then the cells get reused right on screen, appearing and disappearing, which is not ideal.
Any ideas?

Transparent TableView without overlaping elements ios

i want to make a transparent table view but the problem is that when the cells go behind the section headers the texts overlapps(see the image:)
http://www.imagebanana.com/view/4lu0pp8s/Bildschirmfoto20130920um13.20.45.png
my idea was to draw the part of the backgroundimage in the header as background but the drawrect method is not updated when the cells are moved.
Hope someone can help me
You need to trigger a call to -drawRect: yourself by calling -setNeedsDisplay or -setNeedsDisplayInRect: on your header. You will probably want to trigger it based on detecting the position of the header in -scrollViewDidScroll:.
Warning: you will want to figure out whether you need to draw the header and then call -setNeedsDisplay as infrequently as possible. Bitmap drawing is slow, and can cause the UI to stutter. You should only need to do it when a header row hits the top.
If your header rows are all the same size, cache the image after the first time you draw it, and then just reuse it each subsequent time you need it.

How does the Reeder Mac app animate lists when switching folders?

Initially I was under the impression that it uses the table row slideup/down animations while inserting/deleting new rows but I doubt if it's doing that as it does it so fluidly even with thousands of items in the list (otherwise it would take a lot of time for the deletions/insertions to work).
Am I right in my assumption that it's simply attaching a new instance of the News list at the bottom of the screen, shrinking the above one while the one at the bottom expands to fill up space?
UPDATE:
Please see this video of what I mean: http://dl.dropbox.com/u/4960327/ReederAnim.mov
I can not tell you exactly how Silvio Rizzi made this, but as you see in the playback, a list view is added behind the shown list view, and the front list view fades out (.alpha = 0.0;) while the list view behind it expands its height per row.
When you desicate it frame by frame it becomes quite clear what he does, and it is really not that advanced. But I have to admit, with the white "milky" polished interface, it looks quite neat.
In addition, you can see that while animating, the background list view only renders the top 7 entries (hopefully calculated by dividing the view height with the average height of the cells shown) making the list view quick to load. Then afterwards, he can load an extended array of cells once you start scrolling, or in a background thread starting once the animation is complete.

Lazy loading images in a UITableView that has a scroll index

I think this is a new spin on an old question, but I'm completely stuck here.
In my app, I have a UITableView with 650 cells, each with a custom 16x16 RGB icon. On most recent iOS devices, loading all of those icons into memory before displaying the table works totally fine, but on older hardware, I'd like to implement a lazy load system that only loads icons it needs.
I've implemented the Apple LazyTableImages example, (which uses a UIScrollView delegate to determine when the table stops moving to load the visible icons), but I've run into another snag.
My UITableView also has a section index display (ie the list of labels on the right hand side you can swipe up and down to scroll quickly), and the LazyTableImages example hasn't taken this into account.
If I scroll using the index, the images won't lazy-load. :(
As far as I can see, the scroll index doesn't actually have any delegate events it triggers.
So I'm wondering, has anyone else tried to implement lazy-loading on a table with a scroll index? Is there any way to track the index and find out if the user has interacted with it?
Thanks!
After buzzing around a few of my iOS developer buddies, I came up with a solution that worked well enough.
I set it up so that in addition to the icons being loaded from the UIScrollView delegates, an NSTimer object will periodically call a method that checks the currently visible table cells ([UITableView indexPathsForVisibleRows]) every .5 seconds, and loads any icons on the screen that haven't been loaded yet in a single separate thread.
I tried to make the solution as efficient as possible, so I made sure the timer was only active when the tableView was visible and stationary, and I liked it since it meant that every visible icon regardless was addressed.
One thing I discovered was that if the tableView was reloaded while the thread was looping through the visible cells (rare, but was possible), it would crash. The solution to this was to make sure each cell data source entry was retained while the icon was being loaded.