UITableView is getting stuck when loading data from UICollectionviewcell - ios

I have a Uitableview in which i am loading custom uitableviewcells
and all that cells are calling a class which draw a collectionview
with scroll in it depending on amount of data,
so I'have seen that when I scroll then my UITableview take a jam on
those cells which are adopting scrollview then after a very narrow
second everything is fine but when I scroll again then it again
happen
I know that the problem is I am drawing cells on each time but I have
also take a look by initiating an array of views and then pass the
specific view to the cell on run time but strangely it got more stuck
when I am doing this.
Kindly help me on this

My Approach in your scenario would be to create “Section Header” and “Section Footer” for UICollectionView like the approach in this tutorial http://www.appcoda.com/supplementary-view-uicollectionview-flow-layout/ which i feel much simpler and easy to implement.

Related

Looking for the best scroll-view solution

I want to learn and implement the most suitable/simple solution to display dynamic data (JSON) in three lines and an active (clickable) download icon. Screenshot is attached
I would be glad to get your ideas and advice!
Thanks
UITableView is the way to go, as you can reuse a custom cell you define. And to add to that, UITableView's cells are loaded lazily and are reused. You can use a UIScrollView but if you have a lot of rows it can horde your memory real fast. In your case, a UIScrollView can be used as well, but if you plan on expanding, UITableViews would be the choice. All in all, go with a UITableView + a custom UITableViewCell
If you have array of data like this, the best way is using UITableView class. With UITableview, you can custom your UITableViewCell on the fly

tableview smooth scroll best practices swift

It's a technical question, or about good practices...
I have this App, its a social network, where we have the timeline. In this timeline I have to render a lot of cells on a tableview which I have done this way:
create a Cell (with header, body and footer) -xib file
in this cell I have a method: setupCell() - which configures the contents
for each kind of post I instantiate a correctly view(xib) on body of this cell (like PhotoPost, TextPost or VideoPost etc) and configure constraint to set the size of views.
Also, I'm using:
tableView.estimatedRowHeight = 603
tableView.rowHeight = UITableViewAutomaticDimension
And kingfisher to download images asynchronous.
And, what is best way: storyboard, xib, or code?
So, my problem is that my scroll is lagging - I'm using reusable cells, but every time that tableview delegate calls cellForRow, I have to setupCell().
My first idea:
I get the post array with a task then a create cells for each post and append this to an array of cells, so when cellForRow is called I just get the right cell from this array.. It make better. But still not enough(I'm testing on a iPhone 5c).
My next ideia is create different cell for each kind of post, and save a variable for this cell of his size to setup on heighForCell method.
You think that looks good solution? Can anyone give me an opinion and suggestion? I'am very tankful in advance..
After experimenting with possible solutions I decided to use AsyncDisplayKit to solve my problem, it offers great smooth scrolling.
http://asyncdisplaykit.org
It's complete SDK and has well written documentation so was easy to implement. I would recommend it if you are struggling with a similar issue to me.

UICollectionview Scrolling while adding Items is super laggy

I have this very nice collectionview that loads pictures from my server. Now, if the pictures are loading slowly, the collectionview is actually scrollable, but if the pictures are loading fast, instead, the collectionview is basically frozen until all the cells are finally loaded.
I'm pretty sure this is something related to the fact that I'm using dispatch_async to update the ui (inserting cells and sections), so I'm wondering if there's a way to update the ui that still allows me to scroll the collectionview while the items are being added.
Is there anything I'm missing?
Thanks in advance for your help!
The easiest way to solve this issue is to use SDWebImage an UIImageView alternative , and call the sd_setImageWithURL:placeholderImage: method from the tableView:cellForRowAtIndexPath: UITableViewDataSource method. Everything will be handled for you, from async downloads to caching management.
You can find it here: https://github.com/rs/SDWebImage
So remove any dispatch_async, set right away the number of cells on this method:
- (NSInteger)numberOfItemsInSection:(NSInteger)section;
Scroll performance is going to be good with this tool

Nesting UICollectionViews vs UIPageViewController

I found myself in the need to implement the following: scrolling through pages and displaying a tableview or collectionview with the data relevant only to that particular page in the lower part of the screen. First I tried to use nested UICollectionViews making the cell of the outer UICollectionView to be the size of the screen and setting inner UICollectionView's delegate to the containing cell (outer UICollectionView's cell). I ran into the issue of data not getting loaded properly into inner Collection view. The problem is better described in this question:nesting UICollectionViews issue
Anyway, I looked more into UIPageViewController as a possible solution to the problem. I have never implemented UIPageViewController before and not sure if this could be a good fit for my problem. If anybody has done something like that before, please direct me to the right place or resource.
I still would like to go with nested UICollectionViews if possible and I don't quite understand why it is working as desired. Once again my problem is described better in the link above. Please advise on both options.
When using a UIPageViewController you have to implement the reusing mechanism by yourself, that is the only downside i can see. Basically i would prefer UIPageViewController cause it is cleaner then nested collectionViews.

How to reuse UIViews, the way UITableView does?

I want to create a view that shows vast amounts of data. Using UITableView would have been a good idea except it's not the way/style I want to show it. I'm thinking of creating my own view, and I was wondering: UITableViewCell is constantly being reused through the dequeueReusableCellWithIdentifier method; how does this work? I mean, I can figure out how to cache UIViews, but how does UITableView draws them on the table, allowing them to still be interactive, without keeping the UIViews themselves?
Thanks!
Aviad.
Apple's ScrollViewSuite sample code shows how to create a tiled UIScrollView that reuses views very much like a table view. You could use it as a model or starting point.

Resources