I am trying to display my items on collectionview when clicking on a button. It works on Android simulator and when deploy Android from VS. But it does not work on IOS Simulator
Here is my xaml code :
<StackLayout x:Name="WordSListStack" IsVisible="False" Padding="0,10,0,0">
<CollectionView x:Name="WordSList"
ClassId="1" SelectionMode="Single"
SelectionChanged="OnSelectedWordAddDatabase" >
<CollectionView.ItemTemplate>
<DataTemplate >
<StackLayout BackgroundColor="White" Padding="10" Margin="5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Orientation="Vertical">
<Label TextColor="#7D7D7D" Text="{Binding .}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" FontSize="16" />
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
Here is how I load items on collectionview:
private async void OnSelectedLocalPlace(object sender, SelectionChangedEventArgs e)
{
Device.BeginInvokeOnMainThread(() =>
{
WordSListStack.IsVisible=true;
WordSList.ItemsSource = LocalWordsList;
});
}
Here is the error :
The relevant UICollectionViewFlowLayout instance is <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7faaf06e4a20>, and it is attached to <UICollectionView: 0x7faac13c0e00; frame = (0 0; 796 823); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x6000031966d0>; layer = <CALayer: 0x60000354ac00>; contentOffset: {0, 0}; contentSize: {797, 368}; adjustedContentInset: {0, 0, 0, 0}; layout: <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7faaf06e4a20>; dataSource: <Xamarin_Forms_Platform_iOS_GroupableItemsViewController_1: 0x7faaf06e4c50>>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
The behavior of the UICollectionViewFlowLayout is not defined because:
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.
Please check the values returned by the delegate.
The relevant UICollectionViewFlowLayout instance is <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7faaf06e4a20>, and it is attached to <UICollectionView: 0x7faac13c0e00; frame = (0 0; 796 823); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x6000031966d0>; layer = <CALayer: 0x60000354ac00>; contentOffset: {0, 0}; contentSize: {797, 368}; adjustedContentInset: {0, 0, 0, 0}; layout: <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7faaf06e4a20>; dataSource: <Xamarin_Forms_Plat
form_iOS_GroupableItemsViewController_1: 0x7faaf06e4c50>>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
The behavior of the UICollectionViewFlowLayout is not defined because:
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.
Please check the values returned by the delegate.
The relevant UICollectionViewFlowLayout instance is <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7faaf06e4a20>, and it is attached to <UICollectionView: 0x7faac13c0e00; frame = (0 0; 796 823); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x6000031966d0>; layer = <CALayer: 0x60000354ac00>; contentOffset: {0, 0}; contentSize: {797, 368}; adjustedContentInset: {0, 0, 0, 0}; layout: <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7faaf06e4a20>; dataSource: <Xamarin_Forms_Platform_iOS_GroupableItemsViewController_1: 0x7faaf06e4c50>>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
The behavior of the UICollectionViewFlowLayout is not defined because:
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.
Please check the values returned by the delegate.
The relevant UICollectionViewFlowLayout instance is <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7faaf06e4a20>, and it is attached to <UICollectionView: 0x7faac13c0e00; frame = (0 0; 796 823); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x6000031966d0>; layer = <CALayer: 0x60000354ac00>; contentOffset: {0, 0}; contentSize: {797, 368}; adjustedContentInset: {0, 0, 0, 0}; layout: <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7faaf06e4a20>; dataSource: <Xamarin_Forms_Platform_iOS_GroupableItemsViewController_1: 0x7faaf06e4c50>>.
2021-07-30 13:47:17.671882+0200 LeafWords.iOS[53379:807398] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
I had this problem for a long time, to the point that I went to all Listviews.
It turns out that in order for CollectionView to Work in iOS, you must set a SizingStrategy. I don't know if there isn't a default one or what, but that's what was stop me. One of the following must be there:
ItemSizingStrategy="MeasureFirstItem" or ItemSizingStrategy="MeasureAllItems"
This seems to be a bug: https://github.com/xamarin/Xamarin.Forms/issues/13323
According to the information on that page you can use Xamarin.Forms 5.0 pre-release 6 to avoid the problem. It is likely that also some previous regular versions work properly. Also you can try to set ItemSizingStrategy
to MeasureFirstItem
if it is OK for your use case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With