Best way to display tabular data like the attached screenshot in Swift? - ios

I am looking at the lower portion of this screenshot. If I had something similar to this in my design, what would be the best way to set this up in Swift?
I have looked into UITableView, but that doesn't seem to be quite what I need. Most of the tutorials & articles I've read regarding the UITableView only focus on 1 or 2 columns max, and don't really expand on how to go much beyond that.
I briefly considered just doing a bunch of statically placed labels, but realized that I will not always know exactly how many items are going to be in the table, so I need a more dynamic way of going about it.
Does anybody else have any advice on how I might go about achieving this sort of layout in Swift?

There are several ways...
UITableViewCell subsclass. It's perfect for your purposue, and you can design it's contents following your needs. (No matter if 2, 3 or 4 columns)
Combination of StackView Vertical with StackView Horizontal inside. Each horizaontal view will contains one of your row.
Generate a HTML page and injec it in a SFSafariViewController or WebView.
Static content. A plenty of UILabel. One for each piece of information
In my opinion the best aproach is the UITableViewCell subsclass.

Related

What is the best way to make a data grid in swift?

example
Good evening everyone!
Part of my requirements for the app I am building has me creating a data grid similar to the example linked. I have spent the entire day searching google and this site in order to find the best way to get started in swift. I have read so far that both a table view and a collection view could work, but that a collection view is preferred. My data grid doesn't necessarily have to be scrollable but the data does need to be editable. I don't have much experience using either tableviews or collectionviews and I'm looking for the simplest implementation without relying on a third party dependency. Any help or direction is greatly appreciated.
Since I don't know your experience level, I will explain at a basic level - my apologies in advance if it's too basic :) A UITableView displays rows of data, while a UICollectionView displays cells in a grid.
So, at first, a UICollectionView might appear to be the better option. But as always, things get complicated pretty quickly :) For example, are you going to implement your UICollectionView as one cell for the whole row, or are you going to implement a cell per column in your table of data? And if you implement cells per column of data, how are you going to handle the different types of cells you might (or might not) need for each column?
There are multiple decisions that might need to be made, and only you know the answers to a lot of these :)
But the simpler option probably is to go with UITableView and that's what I'd suggest if you are new to both UITableViews and UICollectionView. Try out a UITableView-based approach first and if that doesn't work, or you see limitations, then try a UICollectionView. The experience you had in building the UITableView will help you in moving on to UICollectionView anyway :)

Size Agnostic UICollectionView//UIScrollView

I am trying to figure out if there's a way to create something like a UICollectionView for an arbitrary and potentially infinite amount of UICollectionViewCells. I also want to be able to do fancy things with my own UICollectionViewLayout.
What I'm trying to do is create a dataSource that's a linked-list. So each element in the dataSource knows which element comes before and after it. I have no idea how big the list is. I don't care.
I've looked at the UITableView stuff and it needs to know how many elements are in it. I've looked at the UICollectionView stuff and it ALSO needs to know how many elements are in it. The UICollectionViewLayout needs to know how big the view needs to be (collectionViewContentSize). All of this is frustrating to me because I don't see why this much detail is needed.
For simplicities sake, lets assume that I only need to show ONE cell at a time. I don't see why I can't just tell the View that it's only 3-cells wide (always) and when you scroll to the left or right, pop the cell of the long side and put it on the short side? At no point will I need to be able to say "scroll to 5" I just want to be able to say "next, next, next" or "prev, prev, prev"
What's the best way to capture this behavior?
The best answer I can think of thus far is to basically do what I said w/ the "use three cells" thing. I could just have a CollectionView that is concerned with how to best lay out some n-cells (where n is 3, or 5, or 25, or somethign) and some other thing that is concerned with what to be putting in each cell and while the view is cycling between the same n cells, the data thing is pushing the appropriate data into them?

Implementing chat layout with UICollectionView with AutoLayout

Is what I'm trying to accomplish here even possible? I've been searching for hours for sample code and/or SO answers that demonstrate this simply enough to follow, but so far no luck.
Goal: implement something that looks roughly like this mock:
Yes, I know this is easy with a tableview, but the full design includes custom interactions, multiple columns, UIKit dynamics, and custom animations when adding/deleting cells, so UICollectionView is the better candidate. Until I can get this core layout to work, though, the rest of it is just a pipe dream.
So far I've started with a subclass of UICollectionViewCell that has a single label with constraints to all 4 sides of the content view. At which point I run into these issues:
It's unclear how I can calculate collectionViewContentSize() when the cells don't exist yet, esp. given that the majority of cells are actually offscreen most of the time!
If I just throw in an arbitrary content size (e.g., 320x1000), my views show up, but their heights don't adjust to the label content…I can't seem to read the cell height from within my UICollectionViewLayout subclass.
Seen or done anything like this? I'd include code, but after hours of futzing with it. I'm just looking for a clearer tutorial or sample code that fits this scenario.
There's a project you might want to look at. It's fairly involved and probably has a lot of code for situations that don't quite match yours, but does indeed create a chat view using a UICollectionView.
It can be found here:
https://github.com/jessesquires/JSQMessagesViewController
For item 1 - with regards to calculating collectionViewContentSize, I think you'll find you may not need to calculate that, at least as long as you're using a UICollectionViewFlowLayout subclass for the layout.
And for item 2 - rather than set a fixed 320x1000 take a look at the JSQMessagesCollectionViewFlowLayout.m for sizeItemAtIndexPath.
Sorry, this probably should have been a comment, but I lack the reputation to comment & so I made it an answer (doesn't that seem backwards? Ah well.)

Multiple columns in tableview ios

I am working on an app using objective C and Xcode.
For the moment I am using a table view and returning rows with cells containing an image thumb and title. My problem is that now i need to change the layout and for 4 of the cells I need to make them fall on the same row (so each article of the 4 should be 50% width). So basically create 2 columns but only for 4 of the articles. The rest remain on 1 column (full width).
I would add an image but I don't have enough rep points.
I know there is some thing like collection view...but I am not very familiar with that one and I was hoping maybe there's an easier way than redoing the viewcontroller and all the connections I already have created there.
Since I am already using tableview..what's the best way to change the layout to fit what I need now?
Based on what you're trying to do a UICollectionView might not be the best bet. I would create a second type of UITableViewCell for those rows with 4 columns. This should help Multiple Custom Rows UITableView?
You can use UICollectionView with flowlayout and variable cell width. There are many tutorials about it out there.
You can also try this library: https://github.com/bryceredd/RFQuiltLayout
Have you taken a look at this library:TSUIKit
If you just want to quickly arrange your data, this would be much easier than trying to wrangle with UICollectionView.

UICollectionView VS UITableview

I have an app which will show over a 1000 items, all of those item details are local ( saved via coredaata) and will ship with the app.
In researching the UI mechanisms to show those items, I am in between choosing uicollectionview or tableviewcontroller with a customized cell.
My question is : Which choice would be more efficient and provide a smoother UI in terms of
dragging?
which one can I customize to load out the 1000 entries I have only enough the provide a smooth scroll, and load more cells as needed?
Thanks.
Both approachs will handle 1000 entries easily if you follow the good practices of view/cell reusing. Additionally both APIs are very similar, so jumping from one to the other is not that hard.
The main difference between the two is how you want to display those 1000 items. UITableView has a couple of styles of cells stacked one over the other. You should not try to bend it to do any other kind of things too much complex than that kind of layout. UICollectionView is a much more powerful set of classes that allow to modify almost every aspect of how your data will appear in screen, specially its layout, but also other things. You can see UITableViews in almost every iOS application (for example Contacts or iPod), while UICollectionViews are more difficult to see (the grid in Photos, but also the coverflow in iPod).
So, if you need something standard like most table views in iOS I will choose the UITableView, but if you need more control over your layout, go with UICollectionView.
It's slightly unclear what you're asking, so I have summerized the advantages of both.
UITableView
UITableView is the base mechanism for displaying sets of data on iOS. It's a simple list, which displays single-dimensional rows of data. It's smooth because of cell reuse and other magic.
UICollectionView
UICollectionView is the model for displaying multidimensional data - it was introduced just a year or two ago with iOS 6, I believe.
It's also smooth because of the same tactics used in UITableView - cell reuse, etc.

Resources