ios storyboard duplicated CollectionView cellForItemAtIndexPath not called - ios

Things I want to do
Duplicate a CollectionView From ControllerA to ControllerB in storyboard
Things I have done
Duplicate(CMD+D) CollectionView From ControllerA(which works fine)
Drag Drop to ControllerB
retarget(ctrl + drag) dataSource and delegate to ControllerB
It should be
duplicated collectionView should work fine like it in ControllerA
But result is
numberOfSectionsInCollectionView and numberOfItemsInSection are called
But cellForItemAtIndexPath not called
Edit 1
the problem looks like related to the frame size of the CollectionView
CollectionView: size(320,50) flow layout,scroll horizontal
CollectionViewCell: size(50,50)
If I drag CollectionView height to 65,it works with a warning:(cellForItemAtIndexPath called)
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values.
if CollectionView height >= 114,works without warning.
ControllerA with same parameters size(320,50) will work.don't know why
Edit 2
if I duplicate the CollectionView with all same settings and retarget to same delegate. the duplicate one doesn't work as expected. But the original one works!! weird!!

After upgrade to xcode 6 beta 5, I notice the cell is not in the visible area of CollectionView
Solution:
toggle off Adjust Scroll View Insets option in parent view controller attribute inspector
or add this code to parent view controller viewDidLoad method:
self.automaticallyAdjustsScrollViewInsets = NO;
ref:UICollectionView adds top margin

Related

When I create my 1st CollectionView using storyboard the CollectionViewCell has default insets from top?

When I create my 1st CollectionView using storyboard the CollectionViewCell has default insets from top(in size inspector it shows zero but it bit down from top of CollectionView) and I cant move it to top, but when I create a second CollectionView and further CollectionView its cell has no insets from top?
In your storyboard, uncheck Adjust Scroll View Inset of the view controller containing the collection view.

How to handle UITableView in UICollectionViewCell with interaction in iOS Swift 3?

I have project with structure like:
-scroll view
--view
---collection view
----collection view cell
-----table view
------table view cell
This structure is necessary for this project.
Every things works correctly like scroll view, collection view and table view but there is interaction just with index 0 in collection view.
In other words didSelectRowAt method just call in index 0.
And i have uploaded my project on GitHub:
https://github.com/reza-khalafi/ScrollCollectionTable
Please help me to fix this problem.
Thank you
To fix the offset try using an auto resizable cell for UITableView
so in setTableViewDataSourceDelegate method just call
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 300

Auto set height of table view based on UICollectionView inside it

I have a UITableView with cells that have inside a UICollectionView.
Now all works great except of UICollectionViewCell scrolling i want that the height of table view cell follow the Collection view cell content.
In simple word i want scrolling in table view but not inside single cell i need to display all contents of UIcollectionViewCell without scrolling inside it.
Thanks
You have to calculate the collectionviews' heights and set a height constraint on each of them. then add top and bottom constraints from the collectionviews to their superviews (the tableviewcells / their contentviews) and let autolayout do its work.
don't forget
tableView.estimatedRowHeight = 44 // or something similar
tableView.rowHeight = UITableViewAutomaticDimension
in the controller's viewDidLoad to make the automatic row height calculation work.

How to make a UICollectionViewCell span entire row?

Context
I am trying to create something similar to a Table view using UICollectionView.
I am using Xcode7 and storyboarding.
The way I do it is that I drag the collection view across the entire controller view.
And then I drag the entire cell across the row and align it with the right and left boundaries.
Problem
But, when I place a label inside the cell, then it gets displayed correctly only when the device is in a horizontal position.
When the device is vertical, it gets cut off at the left boundary.
Question
How do I ensure that the width of the collection view cell matches that of the container width?
1) Implement the function of cell size and return the collection width:
-(CGSize) collectionView: (UICollectionView*) collectionView layout:(UICollectionViewLayout*) collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath*) indexPath {
CGFloat height = 50; //set the wanted height
return CGSizeMake(collectionView.frame.size.width,height);
}
2) Reload the collection when the screen size change (i.e. orientation change).
It is because you are not using autolayout. You can achieve this entirely in storyboard or through code.
Using Storyboard
Add UICollectionView in your UIViewController in storyboard.
Drag UICollectionView to fill up in your UIViewController.
Add Constraints as shown in image.
Drag UICollectionView to fill up in UICollectionView.
Add UILabel (Or whatever you want to have in cell). Also add constraints in that element.
Build and run.

xcode 6 : tableview in autolayout is working for some devices but not all

I'm using auto layout to design tableview that uses full margins of the cells and it's working partially.
Also tableView separatorStyle is not working too
class HomeTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
First disable the features width any and height any of both the tableview and tableview cell.
click on pin for image view or view you are using as background of cell select all the constraint left,right,top & bottom.You are selecting left,top,bottom in image above you posted. Deselect the height and width you are showing in image above.
If you want to place the text vew or label or etc in right of the table view then select left,right,top and only height. This would definately solve your problem. i am unable to post the image since i didnt have 10 reputation.Hope it will solve your problem.
Now You can also follow these methods:
iOS - Custom table cell not full width of UITableView

Resources