Swapping out UITableView Sections. New section temporarily overlaps old - ios

See this screencast: http://www.screencast.com/t/4KZu1ZBVDjs
Basically what is happening is that I'm flipping the view, and then as part of the animations of the flip, I'm swapping out sections to show different information.
For some reason when I delete sections and then insert others, or even if I just reload the sections (there happen to be the same number of them), in one direction it temporarily shows the old section below the new. So towards the end of the screencast, you can see the map is showing under the new cell (avatar and label), but then disappears.
It's not related to the flip animation itself. Even with that removed, same problem: http://www.screencast.com/t/iOcNTyDf
This one is a little perplexing.

Reloading the table seemed to be the better solution here, but this definitely appears to be a bug.
Bug in UITableView ( deleteSections:withRowAnimation: )?

Related

Swipe to delete on entire section in UITableView

I have a UITableView which has a variable amount of sections and every section has a variable amount of rows. Every section contains a section header, a section footer and the rows for that section. They are shown and displayed inside a container. Everything up until now works as expected. To demonstrate what my UITableView currently looks like:
I am now trying to implement the possibility to swipe left on the entire section, so that the header of the section, the rows inside this section and the footer of this section move to the left and display another UIView. I am capable of swiping the cells separately, but enabling this feature on the entire sections have caused headaches for the past two days. This is what I would like to achieve:
I have thought about implementing UIGestureRecognizers but I am afraid they might conflict with my UITableView. Also, I started implementing it, but I would not know how to move solely the section on which was swiped to the left.
Then I thought I could maybe implement a UIScrollView as container for each section. How I would accomplish this is still a mystery to me, but it seems like a possible solution if this could be done.
Furthermore I am out of ideas and stuck on how this should be done. It's something I have not found on the Internet so far - at least no working examples of some kind so I have zero inspiration on how to achieve the effect.
I therefor would like to ask if somebody has an idea of how this could work and what I have to keep in mind when implementing this. Every clue pointing me towards a working solution is gratefully appreciated!
EDIT: I have already seen the possible duplicate this afternoon. However, the suggestion there shows touchesBegan() on the header, which does not work in my case as I need the entire section to be "draggable".
I think one way you can implement this is with a vertical stackview containing views that contains a tableview and the trash icon. When a user swipes left on the tableview header, it will show the hidden trash icon in the view. I would think that each tableview only has one section so it will be easier to keep track of which "section" the user has swiped.
I have currently managed to arrange a similar solution. I take the rectangle of the section with rect(forSection:int), add a UIPanGestureRecognizer in which I add a UIView on top of the UITableView if touches began, I calculate the location of the finger and let the cudtom UIView follow. When a certain point (100 from left edge of the UITableView) is reached, the section gets removed with deleteSections(indexSet:with:).
This works. It does the job, but it adds an overlay to the section rather than pushing it to the left.
Therefor I am asking of someone knows if there is any way of setting the offset for one specific section or for an area of a UIView, so I can offset the rectangle of the section. I have been able to setContentOffset on the entire UITableView but this is not the desired result.
If there is no way to do this, I would consider keeping the solution I have now or maybe implement a snapshot feature which takes a screenshot and crops the rect of the frame, adding this UIImage to the custom view to simulate the section. But that would be tricky. Any ideas for this idea are also welcome.

How to animate UITableView rows when IndexPathsForVisibleRows[0] is moved or removed

I am experimenting with the UITableView, but animations are not occurring as I would expect.
Given a list of cells, I want to delete the top-most cell (the item at IndexPathsForVisibleRows[0]), and have all the rows beneath it, animate upwards into their new position.
However, it appears that any time IndexPathsForVisibleRows[0] (or any invisible cell ABOVE the first visible one for that matter) is touched (moved, deleted, etc), the UITableView refuses to animate the results of the transaction.
I have included 2 gifs to demonstrate the issue.
The first GIF demonstrates the desired behavior. I am removing the cell at IndexPathsForVisibleRows[1] (the second on-screen cell).
Notice how all cells below animate correctly into position.
The second GIF demonstrates what happens when removing the top-most cell (IndexPathsForVisibleRows[0]). Note how all the cells below move immediately into the new position, without animation.
(note: the entire table change is wrapped in a BeginUpdates/EndUpdates block).
Am I missing something which causes the 2 scenarios to behave differently, or I have I just stumbled upon a UITableView bug/limitation?
After much investigation, including several new code projects distilling the UITableView down to the various different factors that could be contributing to this behavior, I have found the simple answer.
Don't use the UITableView
I, like many others, have relied heavily on the UITableView in many applications, due to its simplicity and performance, however, if you really want it to behave in fluid, sensible ways, it just cannot deliver.
There are some inherent bugs in it's behavior which don't appear to bet getting addressed by Apple - and not surprisingly, when there is a much better alternative already in the SDK.
Enter the UICollectionView.
I took all my backend logic for and adapted it to supply a UICollectionView instead (all the work took about half an hour), and lo and behold, everything just worked as originally intended.
So, all my code was correct, the UITableView was just getting in the way.
This is how it now looks. Notice have all deletion scenarios animate correctly, no jankiness.
I'm not the first to have found UITableView lacking:
https://pspdfkit.com/blog/2017/the-case-for-deprecating-uitableview/
Additional benefits to UICollectionView:
customizable layouts
easily customizable cell animations
update transaction does not halt currently running scroll animations (this one is great, if you have a background thread refreshing data, you won't get a sudden 'jerk' when rows get rearranged)

WatchKit – Two tables in two pages, second page has first couple of rows super-narrow

I have the following setup in my WatchKit app:
Two horizontal pages, which are configured programmatically via reloadRootControllersWithNames:contexts:
Each page contains a WKInterfaceTable which loads some separate data.
What I’m noticing is that the second page’s table has its content pushed down so that the first row in the right table is positioned somewhere in-between the second and third rows of the left table.
If I load a single table and a single page, everything is fine with either set of content, this issue only occurs when I have two pages, and both pages have a table – the second page has its table positioned low.
Both pages are using the same WKInterfaceController and pretty much identical logic (they’re just loading two sets of data), so I’m not sure why this might be happening.
It’s also worth noting that if I set up the two pages inside the storyboard and link them by dragging and using the “next page” segue, the problem still happens, so it’s not being caused by using reload.
This image shows mid-pan between the left and right page, and shows the gap on the right one (and that weird red stripe occurs twice, and my gut is telling me that it’s setting the width of my first two rows to like, 1 pixel or something).
Any idea what’s going on here?
I had the same problem. I was doing the table config in AwakeWithContent(). When I moved it to WillAppear() it worked fine. I think the problem is that as you are swiping to the scene it is trying to position the table.
WillAppear() seems to occur once the scene has slid in.

Double grid lines on drag?

I have a table with a search bar. I find that when the search interface is dismissed, sometimes double grid lines appear in the bottom half of the grid. One set moves with the finger as you move the table, the other set remains pinned to the screen.
This looks like this:
Reproducing this takes a lot of effort, so I've uploaded a small test project to github.
I've also prepared a QuickTime movie of the bug in action:
The key points seem to be:
Table sections are in use.
A search that returns a small subset of rows.
Things I've tried:
Setting the search result table's rowHeight.
Setting the backgroundColor of both tables and all cells to [UIColor whiteColor].
Tried reloadData on the search results table view instead of self.tableView in updateSearchResults. (This is probably what I should be doing, but it didn't help with this problem.)
Does anyone have any insight as to what's happening here? And, of course, how to fix it.
I ended up using a Developer Technical Support incident for this.
And so, for posterity: This is caused by working at the wrong level; instead of working with the UISearchBar messages, work with the UISearchBarController messages.

UITableView keep the scroll at the correct position while updating NSFetchedResultsController

I am developing an iOS application that mainly use a UITableView.
It retrieves pages of articles from a server. We have got >25000 articles; so I have implemented a pull-to-refresh and infinite scrolling to travel across the title collection.
The ones downloaded persist using core data; NSFetchedResultsController is used to automatically update the UITableView.
However, I have implemented the infinite scrolling to be in both direction; up and down. Since the user will be allow to scroll down the 25000 article titles, I have to remove the one that the user has already scrolled. If the user scrolls up, I have to re-insert title above the current one.
Doing so, I have got a moving window inside the article collection.
I display my articles by date group using the section and header.
The problem is that because the infinite scrolling goes in both direction, I often delete or add article at a higher position in the table.
Infact to achieve that, I have got to change the predicate associated to NSFetchedResultsController.
This result by scroll being messed up. I have made it jump back to the position where it was supposed to be ish. It is not nice because it is a jump (animation:NO), if I put the animation ON, it goes all around the place before going back to the right position. And the position is not exactly the one it should be.
I am not sure I well explained my problem. I think the problem might be in the way I am using the UITableView but I am not sure how I should use it to make this better.
Cheers
If you only store article titles in Core Data, I think it can handle 25.000 titles.
However I think that the problem you've got is with the pagination of the visible elements of the table
Here is a link that I used to handle something that you requested. You'll have to tweak a little bit to use Core Data and a remote source.
Please post some code if you can so we can have a look.

Resources