EXC_ARITHMETIC in UIFlowLayoutSection.updateEstimatedSizeForSection - ios

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.

Related

iOS UICollectionView ConsoleLog Caution when Item Width is bigger than CollectionView width

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!

Full-screen UICollectionViewCell issue on iPhone X in landscape

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

UITableView with embed UICollectionView is not working

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!!

UICollectionViewFlowLayout undefined when I test in devices with smaller screens

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

Autoresize cell xib to tableview cell width and row height

I am currently working with a custom tableviewcell xib and want the size of it to be automatically resized to the tableview's width and it's row's height.
The size of the cell's view does not auto adjusts to the tableview. So I have tried to change the frame inside the tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) delegate no changes are reflected (if I print the frame size before and after it does in fact change.)
Does anyone know a solution for this? The best case would be to make the cell's frame auto adjust to the tableview's width and row height.
Edit: After further examination the problem probably has to do with iOS8 Size classes. When I resize the cell inside the xib, it will just expand to a greater width than the table view's size. The label is supposed to be in the center (had set them with constraints and programmatically, got the same results).
Here's a screenshot:
Found the problem, and it was my mistake. I never set constraints to the TableView inside the ViewController, so it maintained the default base size defined by Size Classes introduced in iOS 8.
That is why the width of the cell expanded about the double of the view controller's width.
What i understand from your Question is You want to set cell's width equal to table's width And cell's height equal to tableviewCell 's height!
By default The height of tableviewCell is 44. So you can set Cell's Height to 44! and you get tableview's Width by
self.tableview.frame.size.width
and You can set cell's Frame by cell.frame!
for Example
CGRect cellRect = CGRectMake(0, 0, self.tableview.frame.size.width ,44);
cell.frame = cellRect;
Hope all things Going Well and that may help you!

Resources