I have a basic UICollectionView and a basic list of items. I've implemented a delete button on the items so that the user can remove some of them. Everything works great apart from the item rearrangement while the item is being deleted.
If you delete the item N-1, it visually deletes the first one in the list, moves the last one to the first position and "reuses all the cells" to set the correct content.
Basically, I would have expected it to move the last one to the N-1 item.
NOTE: This expected behavior happens when I've got one line and 2 items which makes me believe I did things right somehow.
Questions are :
Is this the standard behaviour of a collection view when deleting object ?
How can I fix it quickly without rewriting the whole thing ?
I figured out the problem. It happened that I was posting a notification after the deleteItemAtIndexPath which was actually calling a setter which was calling collectionView reloadData. This reloadData wasn't supposed to be called at this stage so I fixed it and it works like a charm.
So, if you have funny animations make sure you're not calling a reloadData in a way or another.
Related
I ran into the problem that I need to invoke swipes for all cells except the last one by calling SetEdit. That is, I click on the Edit button, a number of cells are shifted to the right and their actions are shown. They should be static in this position and you can, for example, click on deleting or editing a cell. Is this even possible?
I have already tried a lot of things, but I could not even achieve the result.
Thanks in advance !
I'm trying to enable VoiceOver accessibility on my collection view which behaves as follows:
Upon selection of an item, it will remove the rest of the items in the section, leaving only the item that was selected.
When I select the item again, it will re-populate the section with the items that was previously removed.
For step 1, voiceover reads out the item just fine, and it'll be the focus after the layout change.
However, for step 2, things get a bit weird. It'll start reading out the item, and just before it finishes, the focus jumps to another item, and begins reading that one instead.
From Apple's documentation about collection views, it automatically posts a layout change notification when a layout occurs. But, from the looks of it, it's passing on some random element to the first focus element after the layout change.
When a collection view changes its onscreen layout, it posts the UIAccessibilityLayoutChangedNotification notification.
Is there anyway to override this automatic layout changed notification, so that I can pass in the correct focus element?
I found the reason for what was happening.
The reason an element was randomly focusing was because I was calling reloadData on the collectionview in the performBatchUpdate's completion block.
Removing the reloadData solved this problem. However, because I'm not calling reloadData, I had to call reloadItemsAtIndexPaths on specific cells, which is fine in my case.
In my app, I have a very custom UITableView. The cells are all statically defined in Interface Builder, but based on the data structure the table morphs in many various ways. For example, if some data doesn't exist, some cells (or entire sections) are not displayed, custom separator lines are added to account for missing cells, extra views are loaded into the cells, VoiceOver labels change, etc. Because all the cells are static, I set up the table layout in viewDidLoad because I always have the data available at that time. I have always presented this view controller modally, which has worked great. If the user wants to display different data in this table they have to dismiss the view controller and pick a different item to present it again, and it gets rendered appropriately in all cases.
But now I am converting this into a split view controller for iPad, so this UITableViewController never disappears off screen, but I need to set up the table again when the user taps an item. The problem is, because the table is never deallocated, its previous layout still exists when I load more data into it. It would be a lot of work (and an excellent opportunity for many difficult to reproduce bugs to pop up) to test all possible scenarios and try to reset it back to its "pre viewDidLoad state" or undo those previous layout changes if not relevant anymore, if not impossible because I don't have references to the many different custom separator lines generated.
My question is, is it possible to completely reset the table view controller every time a row is selected in the master view controller, therefore allowing it to properly set up the layout because it is not stuck with the previous layout?
I essentially need some way to completely wipe it clean as if it never did any setup, then instantiate it again to cause viewDidLoad get called (or I can move that code to its own method or viewWillAppear). I'm basically looking for a way to reset the tableView back to how it is defined in Interface Builder.
I believe this would result in a flash because the table would completely disappear then reappear in a different format, but that would be acceptable. If that can be animated that'd be nice. If this is really not recommended at all, how do you suggest I proceed to ensure the layout is always appropriate for the data it is presenting?
I was over-thinking this. There's really no need to completely throw away the table and generate a new one. It turned out to be simpler than I had thought to reset the table back to its default state. Just had to be sure to catch every possible thing that could change, including VoiceOver labels, and reset to nil or the default value. Then it can run through the reset code then the layout code every time the data changes and render an appropriate layout. The most difficult part was to remove the custom separator lines, which I solved by adding each one to an array when it's created, then index through it and remove each one from its superview then remove the Autolayout constraints associated with it. One can wrap all of this into a UIView animation block to get a nice fading effect. It's working quite well.
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: )?
UITableView Core Data reordering
I'm having troubles with the solution above. If I do updates one by one (ie one move or one delete at a time) it works when back to noedit mode. But with more updates I get application crash. (I'm using a fetchcontroller)
Could someone try this from a tableview not populated :
- create 3 rows
- hit edit mode and move 1st cell to 3rd position, still in edit mode delete the second cell.
- back to noedit mode it crash for me
Besides this I'm trying to make it work in grouped style and with several sections, where you can move cells to any section. Is someone knows an application doing this correctly ?
Thank you
Well after days trying different solutions it seems I finally get what I wanted.
In addition to Ryan Ferretti solution I had to put a flag to bypass tableview updates when commiting moved modifications on CoreData, to get it work with nsfetchedresultcontroller delegate.
It is describe on Apple documentation, see User-Driven Updates : http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html
I now get a tableview grouped style and can move rows from any section to another one, sorted like I want.
So don't forget this flag. :-)