Uitableview with UICollectionviewcell and UITableviewcell - ios

i need to create below design
I am following this code to draw simple collection view with horizontal scroll inside a UITableView
Current sample code work like this
UITableView-> UICollectionViewCell as cell with horizontal scroll
What i want
i want : First row with UICollectionview with horizontal scroll and
Then rest row with Normal UITableviewCell to show data
How can i do it .

add a UITableView to your view controller and implement it's delegate and datasource methods .(You can use UITableViewController instead of UIViewController).
for the fist cell of the first section in your tableview, you should use a custom tableview cell.
Inside this custom tableview cell, you have to add your collection view with horizontal scroll, and implement its delegate and data source methods inside your custom tableview cell class.
these are the steps you have to do.
refer this implement uicollectionview inside uitableview question for more.
Hope this will help to you.

You should design a UITableViewCell which has a UICollectionView inside, and set this cell for the cell in section A and for Section B, you should design a new UITableview cell.

When tableview's cellForRowAtIndexPath call you can check for First section and when first section load you can create new UICollection view object load in first cell. Than next section will load you can work as normal tableview work.
Not- you need to implement UICollectionview delegate and datasource methods also.

Related

Collectionview inside tableview cell with dynamic height cells and dynamic content swift 4

I am working with collectionview inside tableviewcell in Swift 4. I get the content from server which is all dynamic. I have to show different types of collectionview behaviours.
For example, in the first tableview row should be collectionviewcell with screenwidth and scrollable. In the second row, collectionview with 3 sections and each section has different content different number of items.
Here I got stuck I am unable to show 3 sections one below other it is showing besides horizontally. I have calculated collectionview flow layout size.
Also in last row I have collectonviewcell with scrollable content,here when i scoll the content is repeating from bottom row or top row. I want the smoth scrolling and to stop repeating the content.
I am new to Swift. Can anybody help me out of this . Thanks in advance.
The smooth way is to create tableview with its cell xib and inside its cell add collection view and create another xib for collection view cell. This method is helpful when accessing collection view for different tableview cell. Rather using without loading Xib's may mixup your code.
You have to set tableview cell height as UITableViewAutomaticDimension. This will handle your cell height as per your dynamic content.
For each tableview cell you have to set collection view's property by using cell's index path as per your requirement.

UICollectionView header view like table view header

Is it possible to create UICollectionView header view like UITableView headerView? I mean header view for whole collection view, not the repeated one for each section.
If that's impossible, then how could I add outlets to section view subviews from Storyboard?
Eventually I put UICollectionView in UITableViewCell and added some code to calculate cell height.

UIFooterView not showing when using deque Reusable cell with identifier to get UIView

I am trying to add a footer to my UITableView. I was able to do this programmatically by making a new UIView with the desired height and width and setting the tableView's tableFooterView to this view.
However, I want to use a reusable tableView cell as my table footer. I tried to set the property as follows
myTable.tableFooterView = myTable.dequeueReusableCellWithIdentifier("footerCell") as UIView!
However, the table View does not show up. I was able to get it working when implementing the tableViewforSection delegate method. However, I realized that I need a table footer and not a section footer, since I'm effectively trying to create a custom last cell for my table that scroll with it.
PS: I checked the identifier for my footer cell in storyboard and it looks correct. I also tried creating a custom class for my custom cell and setting the storyboard cell to be of that type, but that doesn't work either.
If you want to use a cell for your footer, and you're using an array to populate your "regular" cells, then return the array.count + 1 in numberOfRows, and put an if clause in your cellForRowAtIndexPath to check if indexPath.row == array.count. If so, dequeue your footer cell.

Using a Custom UITableViewCell with Prototype Cells

For reference, this tutorial I am following: http://mobile.tutsplus.com/tutorials/iphone/customizing-uitableview-cell/
I have to create a custom UITableViewCell, and from the tutorial, it said to leverage Prototyping cells and subclass UITableViewCell. Then connect the UI elements in the prototype cel to the custom class (of UITableViewCell).
The problem I am running into here is, there is only one cell for the whole table view that is displaying data. However, I am able to click on empty cells in the background behind that one cell that contains data. If i scroll up or down, cellForRowAtIndexPath is called and another cell gets displayed. However its only displaying once cell at a time for the whole table view.
Does anyone know what the problem could be here? Any help is appreciated, thanks!
Figured out what the problem is, my labels (that are supposed to be inside the custom prototyping cell) were added to the parent view and not the content view of UITableViewCell. This is because my prototype cell did not have a content view for some reason. I had to add a another prototype cell and delete the previous one.
reference: How to add subviews to a custom UITableViewCell in a storyboard

UITableView inside UICollectionView handling touches.

Collection view consists of a single row, of horizontally aligned cells, which size is the same size as the collection view's bounds, single cell fills entire screen.
The problem is that the collection view seems to be intercepting all of the pans. How can I forward them to the table so I can also scroll the table vertically.
I want vertical pan to be delivered to the table inside the cell, so it can scroll up and down. I want horizontal pan to be delivered to the collection view, so it can scroll horizontally.
Any ideas? Thanks.
For UITableView inside CollectionView using storyBoard, please follow these steps:
-Drag CollectionView to UIViewController, drag datasource to UIViewController(don't drag delegate). Add datasource methods inside ViewController.m
-Create Cell:CollectionViewCell class. choose class for Cell in storyBoard to Cell class,specify reuse ID.
-Drag tableView inside collectionCell square. delegate, datasource drag to CollecionCell Square too. Add tableView datasource, delegate inside Cell.m
-Create CellDelegate when implement tableViewDidSelect inside it. Transfer this delegate to UIViewController to perform other action
Sample code: https://github.com/lequysang/github_zip/blob/master/TableViewInCollection.zip
Swift2 update - We don't need to do all the above steps. Just making the controller the delegate and datasource of both the tableview and collection view works just fine.
I've been able to make this work without using storyboards--although, I use XIBs for my views but only to add the Autolayout rules. All customisation (colors, fonts, labels, etc.) are set in code. In any case, this should also work for cells that are being built programatically.
How to do it:
The most important thing to remember is to add your custom view to the contentView property of the cell and not inside the cell itself. If you are using XIBs for the custom UICollectionViewCell, leave it blank. Instantiate your custom view (where the UITableView is), then add it as a subview of the UICollectionViewCell's contentView. If you add the table vie directly inside the collection view cell, the table view will not vertically scroll.
Implement shouldSelectItemAtIndexPath and shouldHighlightItemAtIndexPath of the UICollectionViewDelegate and make both return false, so that tapping on the collection view cell does not intercept with taps intended for the table view inside.
Done with Xcode 7.3 for iOS 9+.

Resources