UICollectionview with uidynamics reload data issue - ios

I have been working on an app that uses UIDynamics in UICollectionView. I have watched Apple WWDC video and have also tried this sample app in Github.
However, I had this weird problem: When my app launches, I set the number of items for my collection view to 0, the app needs to download something from the server then populate the collection view on the main thread. Weirdly, it's (kinda) reloaded, but not showing anything. I tried on the sample app from Github and it has the same issue as well.
However, if I remove this part:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{
return [self.dynamicAnimator itemsInRect:rect];
}
The CollectionView will show what I want but without the UIDynamics.
I hope the illustration on my problem is easy to understand. Any help will be much appreciated. My guess is I shouldn't use reloaddata.

Related

UICollectionView weird animation (ghost cell, flash) on reload data

Hello as you can see in the video link below when I reload the data, for a frame something happens and some ghost cells appear and disappear, it's like a weird animation... Is it because of using reusable cells? and if it is, is it preventable cause that's not so pretty and it seems to cause a bit of frame drop with use of CATransition animation (not shown in the video). Any help would be appreciated.
Google Drive Link
Video Youtube Link
* EDIT *
Seems the video is not processed by google drive, sorry you gotta download it first to watch it.
Added Youtube link for convenience
Ok I Found the answer myself thanks to all the unnecessary downvotes:
The first solution was to use
collectionView.reloadItems(at: collectionView.indexPathsForVisibleItems)
but that still caused some problem and flicker stuff.
Some other said to use layoutIfNeeded() after that, yet that did not help.
The Solution I Found was to use func reloadSections(_ sections: IndexSet)
so when I use collectionView.reloadSections(IndexSet(integer:0)) (in my case it is the first section) The animation will happen smooth and perfect.

iOS Swift 4 before loading content

I build chat app using Firebase API right now. I wan't to make preload icons like on facebook screenshot. I thought i can create empty images and label fields and fill them after content loaded, but i don't know how to check if all data loaded from DB. How i can do that in correct way?
This is where i want to place objects
Install ListPlaceholder this lib.
import ListPlaceholder
To show the loader, start showing this from start
tableView.showLoader()
To hide the loader, end showing after data has been loaded
tableView.hideLoader()
Please refer this may get help.
https://github.com/malkouz/ListPlaceholder
Facebook has it's own library called Shimmer. To use this on tableview, you can follow this StackOverflow question answer.
You'll just have to create the UIView you want to animate and above that you'll have to add your FBShimmeringView. At the end set shimmeringView.shimmering = true to start shimmering
To hide the loading use tableView.hideLoader()
ListPlaceholder helped me to resolve the issue. All that I did was added the ListLoader.swift file to my project and added tableView.reloadData(), tableView.showLoader() in viewDidAppear in the tableView where I wanted to show loading.
( ListLoader.swif uses visibleCells to determine the number of rows on which the loading should be shown. In my applications, visibleCell's count was incorrect on calling tableView.showLoader() method in viewDidLoad )

Anybody have issues tapping on cells using Xcode7 UITesting?

Anybody having issues tapping on cells where a lot of cells exist? I keep getting the error "Failed to get refreshed snapshot".
I tried using the recorder but that also seems to freeze. I assume it's trying to cache all the cells in the view.
Example: I have cells for each day on a calendar with accessibilityIdentifiers. I have no problems tapping on the cells using the Identifiers with KIF.
Yes, i have. Its about 1 error of 100 tests. Maybe is an apple bug: https://forums.developer.apple.com/thread/6437. I don't know any workarounds :(
A work around would be to tap screen coordinates as mentioned by taylesworth on Apple Developer Forums
Example:
let coordinate = cell.coordinateWithNormalizedOffset(CGVector(0.5, 0.5))
coordinate.tap()

iOS UI Automated Testing: How to pull down, drag or scroll in a CollectionView?

I am testing my app with the UI Automated Testing framework. I have a UIACollectionView I would like to pull down or drag my CollectionView. I already tried the ways from the documentation:
to drag up
target.dragInsideWithOptions({startOffset:{x:0.5, y:0.9}, endOffset:{x:0.5, y:0.2}, duration:2.0});
or to pull down:
target.dragInsideWithOptions({startOffset:{x:0.5, y:0.3}, endOffset:{x:0.5, y:0.8}, duration:2.0});
when this didnt work I tried to use the inheritated methods of the UIAScrollView. chatList is my UIACollectionView
archivedChatCell = chatList.cells()["Noise"]
archivedChatCell.scrollToElementWithValueForKey(1, "isVisible")
chatList.scrollDown()
chatList.scrollToElementWithPredicate("Noise")
But nothing is moving in the screen. I read in some threads that this (dragInsideWithOptions) is a Apple problem that needs to be fixed for the iOS7 UI Testing.
Does someone have any idea what the problem is? Am I missing something or is there a work around for that?
The weird thing is, I am using the same code in a different CollectionView in my App, the dragInsideWithOptions works fine and drags or pulls the screen.
thank you
Yes, dragInsideWithOptions and flickInsideWithOptions are not working on the simulator. However, they do work on a real device. Therefore, my suggestion is to use a real device until Apple fixes the problem.

app freezes on deletion of last row in section ios7

I created an app that used NSManagedDocument and NSFetchedResultsController to populate a NSTableViewController. In ios6 when I deleted the last row of a section it just disappeared and carried on as expected whereas in ios7 the app just freezes and seems to be consuming memory exponentially. I have used the code from the Stanford CS193p lectures to allow the fetchedresultscontroller and tableviewcontroller to combine.
Is this problem a bug in ios7 or does older code need to be updated?
thanks for any answers!
The problem may be that despite deleting the row, the section still exists in memory, try deleting the section using the following method:
[self.table deleteSections:<#(NSIndexSet *)#> withRowAnimation:<#(UITableViewRowAnimation)#>];
Hope this helps!
I found that when I slide the cell to the left to delete it, doing it changes the editing property of the tableview. I had changed the setEditing method to do some custom code for a previous version and so for some reason it kept creating NSIndexPaths. Hope this helps someone in the future!

Resources