UITableView Inside a UICollectionView - ios

How can I set multiple table view data inside a collectionView?

I think its too complex to add multiple table views inside one UICollectionViewCell. Embedded scroll views is not recommended in terms of UX.
But you can do it by subclassing The UICollectionViewCell and be the delegate/datasources of table views.
You can use only one table with multiple sections instead of multiple tables.

You can achieve this by giving tag to each UITableView in all the UICollectionViewCells and you have to manage all UITableViewDataSource and UITableViewDelegate methods by tags of particular tableView.
I know its complicated but you can try this out.

Related

Create a custom scrollable collection view that mimics the behaviour of UITableView in Swift

I have this task that I need to create a custom scrollable view with 3 different types of cells from scratch.(no UICollectionView nor UITableView)
I have no idea what is the best way to start. Wether I should subclass UIScrollview or ...
Any guidance or direction would be highly appreciated.
Create object of UIView, keep adding in UIScrollView depends on your array count.
Keep dynamic calculation for next UIView add subview in UIScrollView
Put transparent UIButton on UIView or use touch gesture to implement like didSelectedRowAtindex.
Another solution we can adapt when there is no UITableView.
Both TableView and Collection View inherits from UIScrollView. So using the parent class could be efficient. But inheritence also serves independent extensions it would also be ok to use the sub classes.
So, Decision depends on what you do. Here in your case.
If one of the cells include a text field for user entry, then scrollview could do better as it offers convienience to scroll/shrink/retain the current UI while showing all the content of UI even when keyboard is present.
If the cells only involve fields like labels,switches,indicators etc then tableview is the choice.
If the cells has non-consistent or non free flow sections then collection view could be better.

How to reuse UITableViewCells

I have 2 viewcontrollers on my storyboard, which both have a tableview. Now I would like to implement the same cells in both tableviews. Is there a way to easily reuse these cells across multiple viewcontrollers?
Yes you can use it by using custom table view cell
Example for custom table view cell
You should reuse full UITableView for this case. There is no open API for sharing cells between multiple UITableViews, but you still can reuse UITableView in case there is no moment when two controllers are shown simultaneously.
Yes, It's possible you need to create .nib file with subclassing UITableviewCell
take a look on https://medium.com/#musawiralishah/creating-custom-uitableviewcell-using-nib-xib-files-in-xcode-9bee5824e722#.u8xounci2
you get to know , how to create & use .nib file.

Same UICollectionViewCell and UITableViewCell in several tables / collectionViews

There are advantages to designing a cell (in a table view or collection view) inside the table/collection, within a storyboard: You get to see the design in context, and you don't have to register the cell in code.
However, it breaks down a bit if you use the same cell in different tables / collection views.
As far as I can see, you have to have copies of the cell design in each table view. This is not very DRY.
I could always use registerNib with a separate xib for the cell, but this removes it from the storyboard.
What is the best practice for doing this? Is there a way to have a reference to a separate cell xib in the storyboard so I can see in in context?
You can do this with storyboard too. Set the custom class for UITableViewCell. You can use the same for multiple tableview.

UITableView inside UITableViewCell - didSelectRowAtIndexPath

I am making an interface which have UITableView with four custom UITableViewCell's. And every other UITableViewCell have also UITableView. This mean I have TableView inside a TableView.
Let me call first tableView - ParentTableView and nested tableView - ChildTableView. So I implemented method didSelectRowAtIndexPath on both tableView's. But when the app is running, only the method of the ChildTableView is being called. I need to know inside the ParentTableView, which cell is being tapped.
How can I transfer that information further from ChildTableView to ParentTableView.
This may be a silly question, but I can not find any reliable solution so far, so please help me.
Thank You in advance, kind Sir
First, I think nested table views is a bad idea. But I don't know your use case, so it might be an exception.
The table view controller class used inside a cell have its own #protocol definition and set the outer table view as its delegate. In the inner didSelectRowAtIndexPath: it can inform the outer table view about the selected indexPath, its own indexPath and any other information you might want to transmit.
Try using collection views. You can do a layout that works like a regular table view and then in the cells that need to have a table, you can make those separate cells with another collection view inside or a table view inside of it.
As mentioned before, it's not easy doing table views inside of cells, and it can be very tricky to get things to work correctly.
This is an old tutorial I wrote which may help and be of guidance. But since then there's been collection views and auto layout, so keep in mind it's very old.

How to Subclass UICollectionView?

I would like to customize the UICollectionView, but all the tutorials on the web and in books use UICollectionViewController which I do not want to use. I'm combining different kinds of UICollectionViews in the same UIViewController, so I don't want to limit myself by subclassing UICollectionViewController, which doesn't allow me to place several UICollectionViews in the same viewController along with other objects and labels.
How do I subclass UICollectionView? Specifically, what kinds of methods need to be overwritten? How do I layout what goes into it (i.e. where to put a text label, image, etc.)? I'm familiar with the data source / delegate protocols, but not quite sure how to customize the cell's look, placement of sub items within the cell, what classes need to be overwritten/sub classed, etc.
A list of things I need to do would be much appreciated!
Thanks!
You can do it like this link
Here are some good Examples to customize your collectionview.
Use WaterfallCollectionView from this. It may help you.
I believe that you don't need to sub-class UICollectionView but you need to sub-class UICollectionViewFlowLayout.
UICollectionViewFlowLayout is the object which manages the display of the collection view items and it is highly customizable.
I suggest you follow WWDC 2012:Advanced Collection Views and Building Custom Layouts
The best tutorial which worked for me was by Apple called Using the Flow Layout.
I think you wont have to subclass a collection view. What you would need instead is subclassing UICollectionViewLayout to customize the positioning of cells within the collection view. And if you are looking for a customized look of a cell, you would also have to subclass UICollectionViewCell and assign the sub classed cells to the Collection View.
The below links might help you,
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CreatingCustomLayouts/CreatingCustomLayouts.html
http://adoptioncurve.net/archives/2012/09/a-simple-uicollectionview-tutorial/

Resources