0

I understand that this is not the only question on the topic but I do need to create a table with rows and columns using Swift and answers to other questions seem to be uncertain and very "hacky".

I had a shower thought that it might be a good idea to generate the table using our web service and then embed it into the app, does this sound wise?

From what I understand Swift/Objective-C does not support a native form of a table view with columns and rows. Am I correct to think this? Is it possible to embed a table printed onto a web page into a Swift app?

1

1 Answer 1

1

I'd recommend checking out UICollectionView, the more flexible counterpart to UITableView. With UICollectionView, Apple introduced flexible layouts that allow you to customize any sort of arrangement you want. Grids were one of the principle use cases in mind when the API was built, and UICollectionViewFlowLayout can get you up and running in just a few lines. Try something like this:

UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
layout.itemSize = CGSizeMake(width, height); // the size of your grid's 'tiles'
layout.minimumInteritemSpacing = interitemSpacing; // a CGFloat specifying horizontal space between tiles
layout.minimumLineSpacing = lineSpacing; // specifying vertical space

UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:layout]; // layout must not be nil!

And then finish initialization and setup per Apple's documentation. It's worth mentioning that you of course get all the goodies of UITableView (cell reuse, etc) with UICollectionView - just with way more layout flexibility. Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.