Convert Complex UITableView to UICollectionView - ios

I currently have a prototyped UITableView in my storyboard, which has many cell with very complex layout. Now, I need to convert it into a UICollectionView, because I always have some problem with the way UITableView handles cell layout(See my this question). I figured the code part to be the easy one, as I only need to tweak the inheritance of my cell classes, as well as switch the delegate and datasource with previously written code. However, I am a little stuck on the storyboard side, that is, given all my cells are complex in layout and even copying and pasting them from one cell to another would require many layout tweaking and IBOutlet/IBAction reconnecting. Is there a fast way to convert those UITableViewCells designed in storyboard into UICollectionViewCells?

I think, you save data into one class, In CollectionView, You get data from class. You remember, tableview and collection are reverse about cell and row.

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

UITableView vs UICollectionView vs UIScrollView?

When should I use which, and what are the disadvantages or disadvantages of each? I'm mainly confused with scrollview vs collectionview, I know tableview is limited to one column (I heard it gets messy when more than one column), but scrollview difference with collectionview seem the same to me.
Both CollectionView & TableView are basically subclasses of UIScrollView.But as compared to UIScrollView here you are provided with proper methods to provide your dataSource & delegates to handle operations user performs on data. Along with this you are provided predefined layout classes.
Now to choose between them completely depends on your UI Requirements. Suppose you want to display just a list of items with a simple UI go with TableView.If you want a custom Layout like a grid or like the one you see in Apple's photo's app CollectionView is the choice.
if you have a complex UI & you have no idea about Custom CollectionView layout classes go with scrollView.
Consider UITableView and UICollectionView first and if you cannot achieve the effect you want with them, try UIScrollView then. UIScrollView is more basic class. UITableView and UICollectionView have more delegate method for us.
If you want a list,UITableView would be better. And if you want a multicolumn,use UICollectionView.

Reusable identifier cells versus returning a cell subclass?

I create my table view cells in xib files that I then register with my table view and return in cellForRowAt using the tableView.dequeueReusableCell method. In the rare instance I create cells by subclassing them and manually programming the interface I usually just initialise them and return them from within cellForRowAt.
I recently discovered that you can register subclasses using tableView.register(cellClass: AnyClass?, forCellReuseIdentifier: String). Should I be registering my subclasses and returning them via dequeueReusableCell? What are the benefits of using it instead of returning an initialised subclass?
You have to always register cell(via code or in storyboard). The Reusability principle is the most important in iOS Table and Collection views.
It means that the table view draws and stores in the memory only few cells that are currently visible + several that mat be visible in the nearest future. If you will not use reusability you will have a big performance problems with big amount of cells.
Also don't forget to clean cells ui in prepareForReuse method in cell subclasses
Yes, you should be taking advantage of the cell reuse system. The reuse system allows the system to very rapidly respond to scroll actions on your table. Instead of having to instantiate a whole new cell from scratch the system can just take cells it already has and update their content.
Bypassing that system by making a whole new cell every time is not an ideal use of resources and with more complex cells can result in noticeable lag on your table view.

Swift custom cells layout TableView decision

I need to display a table with in my iPhone app:
neither the number of cells nor the contents are known at compile time, but only at run time.
Views for each cell may differ, one cell has textField and another may have some other view control.
Should I consider Static or prototype cells?
Should I consider tableViewController or viewController with tableview in it?
Any thing I need to consider before I start coding? Thanks in advance
For The issue of dynamic Number of cell at Run time, you can call reload data for table view at any time you have the data source ready.
Prototype Cells should be used with no problem.
Simple Table View will be sufficient for the task.
You have to make cell, either in code or in storyboard, for each type of cell you want, 1 table View can have multiple types of prototype cells, Just name them differently and then make the objects of only the specific cell of which the data is best suited.
It is not that difficult but do handle the data source with extreme care.
Should I consider Static or prototype cells?
If you know all possible subview combinations that your cells might need to display the data appropriately, and they are relatively few, make one prototype for each. for example:
One text field,
Two labels,
One image view and a label,
...etc.
Otherwise, just use the plain-vanilla UITableViewCell (no subclassing) and remove/add subviews at runtime when reusing them (that is, inside the method -tableView:cellForRowAtIndexPath:).
Should I consider tableViewController or viewController with tableview
in it?
The only reason I would choose UIViewController + UITableView over UITableViewController is if -for example- I needed the table view to only take up part of the main view's bounds/screen, and display some other subview in the remainder. Otherwise, you get so much "for free" with UITableViewController that there's just no point in implementing all of that from scratch.
You have to choose prototype cell, u can create different types of cell depending upon your requirement.Any think ok for u, u can create tableview controller or view controller.

Custom UITableViewCell using storyboard with some cells

I have a TableView in which a most cells are pretty standard. I make them buy using static cells in Storyboard. However, one cell I would like to customize probably using an XIB file so I would need to load it programmatically.
In the TableView's data source, is it possible to handle loading XIB view for this particular cell only, while leaving other cells to what's delineated in the static cells in the Storyboard? Or is it an all or nothing thing where I need to just give up using static cells altogether?
The rationality for doing this is that I would like to make Storyboard to look as close to the real thing as possible. Right now if I provide a data source, the static cells in the storyboard would have no effect on the actual output and is not in any sense linked to the actual output.
Yes, it is possible. Set the custom class for the custom cell. If you wish to customise it from code, just connect it as an IBOutlet to the UITableViewController.

Resources