Call "cellForItemAtIndexPath" before showing ViewController? - ios

I have an app with custom calendar constructed from a UICollectionView. When I load a month for the calendar, I'd like to pre-load the previous and next months so that I can quickly swipe forward or back without delay.
Right now there's a delay in loading the next or previous months after swiping, and in instruments a lot of the delay is attributed to the UICollectionView cellForItemAtIndexPath method.
Is there a way to force that method to run without showing the view controller? I need to do that for the previous and next months and that should reduce the transition time by about 400ms.
Possible? Thanks for your time

Related

swift segue new viewcontroller stuck when other tasks loading on background

Currently, I have a UItableview which loads based on API. And when clicking on a cell, it segue(show e.g.push) to another viewcontroller. It displays all the cells after the first API call, then it calls other APIs and loads other data(which takes a while and also uses cpu heavily), but the scrolling seems to be smooth when loading.
However, when not fully loaded, if I click on a cell and the other viewController pops up, the entire app freezes for a moment. (The new viewController has all the content displayed, just not responsive)
Is there a solution for this?
What I can think of right now is to decrease the CPU load by loading fewer cells at a time.
Typically you are not going to want to do this:
"loads other data(which takes a while and also uses cpu heavily)"
The better solution would be to not call your second call to fetch all the data and just fetch the data needed to show on your next view controller you are segueing to. Typically done by passing an ID in your API call. So on your tableviews didSelectRowAt you would make the api call to get your data needed that is specific to the next screen, then segue.
If this is not possible due to server side limitations, then you are going to want to chain your first two calls. Meaning don't even show the table view cells until you have all the data.

How to handle timer time and functionality in UITableView Cell

I'm adding a timer in every cell and every cell has its own time, API send me the expire time to alarm the user i need to play timer on the expire time for every specific cell, i'm facing problem when i scroll the table view and it deque the cell then timer does not work properly, And how i can handle it for those cells which are not present on the screen. suppose my array has 100 items but at the time i can show only 10 item on screen then how i'll check and alarm the user for 20th or 30th cell (item).
And how i check alarm for every single cell. Please explain it.
i've tried with indexPath but its not helpful for me for those cells which are not on screen and making issue on scroll.
You should try to set timer in Model. if you are work on Model-View-ViewModel...second update your elapse time when your app will come form background state(if your app doesn't support background modes)

PerformSegueWithIdentifier() takes noticeable longer when it is performed the first time after launching the app

I am calling PerformSegueWithIdentifier() to show a second UIViewController when a cell in a UITableView is selected. The problem is that when a cell gets selected the first time after the app was launched the segue takes noticable longer (maybe around 1 second) than normally. The second time, third time and so an a cell gets selected the segue is performed immediately. After restarting the app the first segue after a cell gets selected takes again much longer.
My Code is written in C# (Xamarin.IOS) but it is principally the same in Swift:
DispatchQueue.MainQueue.DispatchAsync(() =>
{
ShopVC.PerformSegue("DetailSegue", tableView.CellAt(indexPath));
});
As you can see I have already searched for a solution an come up with this one to call the main thread but this doesn't solved my problem at all.
I would appreciate every suggestion. It is no problem when it will be written in Swift. I think it could help more people.

iOS chaining together animations for scrolling table view

So this is a rather simple problem that I've had a rather hard time fixing. I'm trying to take advantage of table views for displaying a huge list of cells because it is already optimized for cell reuse and saves me time in that regard. I need this list to smoothly scroll at an accurate duration. If I scroll too fast cells are still loading when they show on screen so I'm only scrolling one cell at a time.
The code I'm currently using is modified from here: https://stackoverflow.com/a/17956396. I've changed it to only add a single animation to the array and to never remove it. Instead I have a counter that checks to see if there is another cell before scrolling.
This is working fine, but my issue is that I can't update the animation duration to be faster or slower to keep an accurate pace. Is there a way for me to chain animations in a way that would allow me to dynamically update the duration so as to keep accurate timing?

iOS UICollectionView lags with scrolling at start

I use a simple UICollectionView in ma iOS in my project.
The view loads about 100 Cells. The Problem appears even if a let the Cells empty.
After ViewDidLoad the Collection view Appears. When i start Scolling about the first three screen Pages down it lags - even with empty cells!
after that i becomes smooth. I also can get top of the page and try again. Scrolling kepps smooth.
2 reasons that you might also encounter
1. Google analytics
If you set up to count every cell view. It starts fast but then slows down and lags because google analytics writes i/o (maybe some caching) as you scroll too fast.
2. DateTime Parsing
DateFormatter is hard if you setup for every cell. Make sure you have a singleton if possible.

Resources