I have a UITableView with 4 UITableViewCell inside. I want it to be dynamic by setting:
tableView.estimatedRowHeight = 44
tableView.rowHeight = UITableViewAutomaticDimension
For the third cell, with embed UICollectionView, it has 20 UICollectionViewCell.
When i run my project, the uicollectionviewcell return (44, 44) and it display these error:
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, minus the content insets top and bottom values.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fe028c25bd0>, and it is attached to <UICollectionView: 0x7fe029884800; frame = (20 0; 335 44); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x60000024bbb0>; layer = <CALayer: 0x6000002269c0>; contentOffset: {0, 0}; contentSize: {0, 44}> collection view layout: <UICollectionViewFlowLayout: 0x7fe028c25bd0>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
Thanks in advances.
Well the debugger is telling you what is wrong:
frame = (20 0; 335 44)
This is your collectionView frame and this means the height of the collectionView is only 44px, which is also the height of your cell. So it doesn't fit in the collectionView with the cell inset values...
Check your collectionView frame and autoLayout constraints
Increase height of your collection view or decrease height of your cell of your collection view because your collection view's height is 44 and cell's height is also 44. your cell's or item's height must be less then collection view's height!!
Related
I'm using UICollectionView for my project and I put bigger Item than collectionView width to hide selectionButton/DeleteButton and show them when Edit mode or Swiped
Everything is working good but there's caution message in ConsoleLog EveryTime
As I know, there're some Messages I can ignore But I want to know if it's Okay to ignore it
Is it okay to put bigger width for item than collectionView width and ignore that Message?
I don't want you to waste your time with reading every Single line of my code and fix for me
So, I just hope to hear your Idea and if there're some points I should be careful when I using this Way :)
2020-11-01 19:08:14.917103+0900 IssueTracker[27304:7532603] The behavior of the UICollectionViewFlowLayout is not defined because:
2020-11-01 19:08:14.917210+0900 IssueTracker[27304:7532603] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
2020-11-01 19:08:14.917241+0900 IssueTracker[27304:7532603] Please check the values returned by the delegate.
2020-11-01 19:08:14.917601+0900 IssueTracker[27304:7532603] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x10571ae80>, and it is attached to <UICollectionView: 0x10a811800;
frame = (0 172; 414 515); clipsToBounds = YES;
autoresize = RM+BM;
gestureRecognizers = <NSArray: 0x2829d5290>;
layer = <CALayer: 0x282780ea0>;
contentOffset: {0, 0};
contentSize: {414, 101};
adjustedContentInset: {0, 0, 0, 0};
layout: <UICollectionViewFlowLayout: 0x10571ae80>;
dataSource: <IssueTracker.IssueListCollectionViewAdapter: 0x28279a2c0>>.
I think that the best way to implement it is by disabling buttons and animating their appearance by changing alpha of text colors. I implemented it this way in my video application and it works perfectly!
In my app, I present a view controller modally, and this view controller contains a UICollectionView that fills the superview. Each cell in the collection view needs to be full-screen - the same size as the view's bounds. To accomplish this, I simply set the itemSize of the UICollectionViewFlowLayout to be the view's bound's size in viewDidLayoutSubviews.
This works really well on all devices and orientations, except iPhone X in landscape. When presenting that screen in that case, it seems the safe area layout margins are coming into play and affecting positioning of the cell. The cell is pushed over from the left edge of the display, and pushed up such that the bottom of the cell is aligned to the vertical center of the home indicator. Inspecting the layout with View Debugger reveals the collection view fills the screen, but the cell's Y position is -10.67 and the X position is 0, even though it is inset from the leading of the collection view. Notably, this is logged in the console:
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, minus the content insets top and bottom values.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fa6311253b0>, and it is attached to <UICollectionView: 0x7fa63207e800; frame = (0 0; 812 375); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x608000244d70>; layer = <CALayer: 0x60800023ef00>; contentOffset: {-44, 0}; contentSize: {0, 812}; adjustedContentInset: {0, 44, 21, 44}> collection view layout: <UICollectionViewFlowLayout: 0x7fa6311253b0>.
What's going on here and how can this be resolved?
By default, iOS 11 automatically adjusts content insets for iPhone X in landscape, causing this issue to occur. To resolve it, you can simply disable the automatic content inset adjustment, as it's not needed nor desired in this scenario.
collectionView.contentInsetAdjustmentBehavior = .never
To the point:
This is happening only when I test in smaller screen sizes because looks like the cell size fits only with iphone 6+.
What I would like to know is how to set a size that fix with all devices?
Details:
I know this question existshere and here but I've tried everything said in the first question and in the second one it's different because they only manage to solve a specific problem that happens when they change from portrait to landscape and the size of the cells changes. In my case my app is portrait and the size of the cell is not set to be bigger than it's container in storyboard, as you can see in the pictures. But look like the size only fit with an iphone 6+ screen and when I use a smaller device I have this warning:
the behavior of the UICollectionViewFlowLayout is not defined because:
2016-08-25 12:27:12.719 xxx[2722:761734] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
2016-08-25 12:27:12.720 xxx[2722:761734] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x15a018930>, and it is attached to <UICollectionView: 0x156994000; frame = (14 287.5; 292 45); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x159dd0020>; layer = <CALayer: 0x159d55dd0>; contentOffset: {0, 0}; contentSize: {572, 0}> collection view layout: <UICollectionViewFlowLayout: 0x15a018930>.
2016-08-25 12:27:12.720 xxx[2722:761734] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
I have set a symbolic breakpoint but the only thing I see is this:
My cell size and collection view size is here :
The size of the cell is equal or smaller in all the cases. The only thing I change in code is the height of the collection view that contains the cells. And I set its size bigger, to allow more cells in the case there are more cells to display.
What I would like to know is how to set the correct values of the UICollectionViewCell size for each device, and what it cannot be done in storyboard??
Thanks a lot
I get the following error in simulator when trying to display a UICollectionView:
UIKit`-[_UIFlowLayoutSection updateEstimatedSizeForSection:]:
...
0x106d32858 <+582>: movq 0x416909(%rip), %rcx ; _UIFlowLayoutSection._validItemRange
0x106d3285f <+589>: xorl %edx, %edx
-> 0x106d32861 <+591>: divq 0x8(%rcx,%rbx)
Thread 1: EXC_ARITHMETIC (code=EXC_I386_DIV, subcode=0x0)
I have set the estimated cell size correctly and also set the collection view height bigger than the cell height. All insets have been set to 0. But before the crash I still get the following warnings:
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, minus the content insets top and bottom values.
Please check the values return by the delegate.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fe65d28b7c0>, and it is attached to <UICollectionView: 0x7fe65c859000; frame = (5 63; 365 110); clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0x7fe65d28bea0>; animations = { opacity=<CABasicAnimation: 0x7fe65d702fd0>; bounds.origin=<CABasicAnimation: 0x7fe65d704610>; bounds.size=<CABasicAnimation: 0x7fe65d704630>; }; layer = <CALayer: 0x7fe65d03a0b0>; contentOffset: {0, 0}; contentSize: {1798, 110}> collection view layout: <UICollectionViewFlowLayout: 0x7fe65d28b7c0>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
Any ideas?
I fixed this by setting the UIImageView size to fixed in the collection view cell instead of having constraints to stretch the image view to the size of the cell.
This is weird because UICollectionView should not scale the cell to larger than the size returned in the dataSource. Also, what has the UIImageView size got to do with the cell size when it has clipsToBounds = true? UICollectionView shouldn't even know what views the cell contains as long as the cell itself has the correct size.
Yes, I have set the contentsize. When I do an NSLog of the contentsize I get a height of 0 and a width of 0 which is a little confounding. It seems like my scrollview doesn't actually exist.
I think I'm setting up the scrollview wrong.
In IB I have a viewcontroller subclass that has a scrollview, inside the scrollview are other labels/views/etc.
Does the scrollview need to have a single subview that manages the "actual" subviews or something?
When I run an NSLog on the scrollview it comes up with this:
Scrollview: <UIScrollView: 0x81b2960; frame = (0 0; 0 0); clipsToBounds = YES; autoresize = TM+BM; gestureRecognizers = <NSArray: 0x81b2dc0>; layer = <CALayer: 0x81b7390>; contentOffset: {0, 0}>
The scroll view does not need to have a single master subview. I'd bet dollars to donuts you have forgotten to hook up the IBOutlet that should point to your UIScrollView in the xib file.
Okay, I figured it out, I needed to have the contentsize code in a viewDidAppear method not in a viewDidLoad method. It's weird because the other changes were being made, just not this one. Go figure