Generate viewcontrollers for every day of the year - ios

So the point is that I would like to have a viewcontroller for every day of the year in my custom navigation bar menu. I am using PagingMenuController library as my menu. There does not have to be 365 menu tabs, the interval can be like 90 days and every time the day changes it deletes the first day from the array and creates new one as last day of the array.
Basically is there a way to achieve it any way painlessly?
The app called ClutchPoints has this feature and I would like to get the exact same result.
This might be too much but I really hope there are some generous people out there who can help me.

Don't create 365 (or even 90) views at a time. You will have serious memory/performance problems if you do that.
You should look at the way table views, collection views, and UIPageViewControllers work. Those all only create the small number of views/view controllers that are actually visible at any one time, and configure the visible ones based on a data source that has the array of data that is being displayed. The views are recycled in order to manage memory.

Related

Imitating split view animation used in iOS Calendar app

I am currently experimenting with a calendar framework I found online which possesses most of the functionality I need. However, I would really like to add a feature similar to the animation in the iOS Calendar where when a date is tapped, the view splits at that location and the selected week moves to the top of the calendar. Its an intuitive way to display info about the selected day. I just need some suggestions as to how this can be achieved since I'm not super familiar with collection views.
The calendar is a grid collection view with months as different sections from what I understand. Is it possible to just stick a supplementary view anywhere in a collection view dynamically? Or maybe I should look into adjusting insets at a specific location? I'm really not sure what direction to take and could use some suggestions.
Here is sort of what I want to do but with a table view.

Loading and displaying random cells in UICollectionView

Pre-requisites - Environment: iOS 9.0 or above - using Swift 3.0.1
Thanks for your responses. I'm updating the question and trying to give a better understanding about the problem.
Posting code would help may be but I'm not allowed to post the code as I do not have the IP.
But I am trying to build something like calendar/program guide where you have events for each category for several days.
Imagine, categories on your left side in a column and they can be the sections of the collectionveiw and each category has events for several days which is a row.
CAT 1 : Event 1, Event 2 ... Event n
CAT 2 : Event 1, Event 2 ... Event n
CAT 3 : Event 1, Event 2 ... Event n
.
.
.
CAT m : Event 1, Event 2 ... Event n
Problem: The entire data is pretty dynamic and humongous. I can't prefetch all the records, they are about over 80-100K. It takes few minutes to download all the data and display it on the grid.
A user could select any day and any time and I have to scroll the collection view to that day and time and display those events for the categories. Also, user could obviously scroll in both directions to and browse the events in this case the events are loaded like infinite scroll fashion.
In the former option though, when the user jumps on to a particular day and time on the entire timeline and I have to skip loading the other previous events (as I do not have them yet - unknown) and display the events relevant to the user selected days and time.
I do not have all the IndexPaths in advance, to display on the screen, how can I skip events and dynamically update the collection view in parts like we load images dynamically and the ones which get loaded first and displayed earlier than others.
I'm using startDate of the events to calculate the xPosition, categories don't change often after they are loaded so we could somehow avoid reloading sections but items in those sections change all the time and they appear in a random fashion.
When the controller loads the first set of events are fetched from the server and displayed, now if the user decided to jump to some D-Day and T-Time which could be anywhere on the entire timeline I have to fetch the events for those dates and populate the items for relevant sections (visible on screen) and update the interface. This is where I have issues, where I do not have an proper approach.
Hope this is clearer.
I have "tried" to mock this up
UICollectionViewFlowLayout can help you achieve what you want...
https://developer.apple.com/reference/uikit/uicollectionviewflowlayout
https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/UsingtheFlowLayout/UsingtheFlowLayout.html
You have the same problem I had with my calendar project. The solution I have implemented will not work for you, but I am mentioning it here so that it might give you clues on how to solve it for your situation.
My calendar has a function where a user can scroll to some date way into the future. The problem was that date cells can be custom sizes. Therefore, since they are scrolling to some future date, in order for me to know the destination offset, I needed to know the offsets of cells 0 -to- destinationOffset because the cell sizes are different. This meant I had to query the sizes of all the cells in the middle which led to a 2-3 lag time (or in your case, a long download time).
So here was my solution.
I originally had a delegate function called sizeForCellsAtMonth which was called for every month in order to determine the size. I have now changed this function to be called only once.
The function now only has two parameters:
defaultSizeOfCells
exceptionToDefaults - this will be specific months where the cell sizes are different
Using this information, I can calculate the sizes of all months because I know the sizes before hand. So my problem was solved by changing the way I looked at my delegate. Maybe you can try looking somewhere along those lines or maybe my answer gave you clues of what you can do.

Swift 2 Date Picker

I have been messing around with date pickers for a university assignment and I came across something that is giving me trouble. Here is the layout of part of my project, which I will explain after the picture.
Basically, I have a date picker on my daily goals view controller. I want to be able to pick a date, then press the button "View Day", which will then direct me to the view controller on the right side of this picture. The view controller on the right will display goals for the day that was picked by the previous action. I can then add/delete goals for that specific day.
Now, I have looked at a few different ways of implementing this functionality. I would like to use core data to store arrays with indexes that point to specific days and goals for those days; however, I do not know how to implement this.
One idea would be for me to create an array of dates, which would point to arrays for specific dates. With these arrays for specific dates, there would be an array of goals for each specific day.
If anybody has any ideas on how to implement this functionality or any pieces of code or references that I could use, I would be very grateful!
Thank you!

how many cells to commence with in a UICollectionView for a Calendar? (i.e. with infinite number of dates)

How many cells to commence with in a UICollectionView for a Calendar? That is my understanding is:
UICollectionView is good in that it only instantiates cells it
needs to display, but then
You still have to add the cells to the collection view
So what is best practice if say your view would only show 10 cells, but you had unlimited cells (e.g. scrolling up and down dates in a calendar). Do you enter say 100 cells for 100 dates (say 50 either side of the starting date of interest) and then manually keep track of when you get to one of these edges and then add more? This would kind of be ashame the UICollectionView framework couldn't keep track of this itself no?
So overall questions therefore (sorry) are really:
How many cells (dates) should you be creating in the collectionview. Should it be limited therefore to say 100
Is there no support in UICollectionView to automate adding more cells in for you for a Calendar type situation where dates are endless if the user wants to keep scrolling forward or backward
Any what is impact on the caching strategy for UICollectionViewLayoutAttributes too?
There is a project on Github with a calendar based on UICollectionView
https://www.cocoacontrols.com/controls/rsdayflow
I have used this component in a production project.
You can easily change it's appearance since every day is a uicollectionviewcell.
This project is based on https://github.com/evadne/DayFlow
that can be a good base to create what you need.
If you want to build your own calendar it can help you to find response to your questions: the code is easy to understand, and the implementation is in my opinion quite neat
It depends on how much is visualized in one screen. If it is one month i would have one month before and one month later. If it is only a day, one day before, one day later. Then use this infinite scrolling trick. There are many examples outside. I didn't read through the following link, but the pictures visualize the idea nicely:
Building a Infinitely-Scrolling Gallery With a UICollectionView

How can I implement an iOS calendar picker similar to Hipmunk's?

I'm working on a couple of iOS apps that require the user to select a calendar date, and while the built-in date picker widget is all right, I'd much prefer if users could choose days from a calendar grid, similar to how it works in Hipmunk's iOS app. In that app, users are shown an infinite scroll view showing a grid of days, with each cell showing the month and day. The days of the week are shown in a persistent (i.e. non-scrolling) banner.
In addition to simply showing a calendar, this control should allow dates to be highlighted/selected. Better still, users should be able to select a whole range of dates by tapping on the start and end days' cells, at which the whole range of days should be highlighted.
Any ideas?
It's an "infinite" UIScrollView with various other views inside of it. Apple provides a demo infinite UIScrollview in their StreetScroller project.
You'll be allocating and initializing views for the various things you wanted displayed on each day, and probably reusing views at the top for the dates (as one scrolls off to the left you change the date and move it over to the right, reusing it the way a UITableView traditionally does).
Selection is a matter of changing visible state of the objects that back your views.

Resources