【Bug】MAUI:NSInternalInconsistencyException Reason: Collection view delegate returned a negative size
【Bug】MAUI:NSInternalInconsistencyException Reason: Collection view delegate returned a negative size
文章目录
问题
NSInternalInconsistencyException Reason: Collection view delegate returned a negative size {440, -12} from -collectionView:layout:sizeForItemAtIndexPath: for item 0 in section 0, which is not supported by flow layout. Delegate: <Microsoft_Maui_Controls_Handlers_Items_CarouselViewDelegator: 0x60000c030a30>; collection view: <Microsoft_Maui_Controls_Handlers_Items_MauiCollectionView: 0x147918400; baseClass = UICollectionView; frame = (0 0; 440 208); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600000d39bf0>; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x6000048829e0>; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 0, 0}; layout: <Microsoft_Maui_Controls_Handlers_Items_CarouselViewLayout: 0x10ee77d40>; dataSource: <Microsoft_Maui_Controls_Handlers_Items_CarouselViewController: 0x146413c00>>
'Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Negative sizes are not supported by flow layout. Collection view:
问题代码
<CarouselView Loop="True" Margin="0,0,-15,0" HorizontalOptions="End" x:Name="carouseView" Position="{Binding Hour}" IsScrollAnimated="False" CurrentItemChanged="carouseView_CurrentItemChanged" HeightRequest="208" PeekAreaInsets="110">
<CarouselView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical"/>
</CarouselView.ItemsLayout>
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="CurrentItem">
</VisualState>
<VisualState x:Name="PreviousItem">
<VisualState.Setters>
<Setter Property="Opacity"
Value="0.5" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="NextItem">
<VisualState.Setters>
<Setter Property="Opacity"
Value="0.5" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="DefaultItem">
<VisualState.Setters>
<Setter Property="Opacity"
Value="0.25" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Label Text="{Binding}" Margin="32,10" HorizontalOptions="End" TextColor="#E6FFFFFF" FontSize="16"/>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
原因
CarouselView的Bug,Orientation="Vertical"且PeekAreaInsets>0在ios端就报错:
<CarouselView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical"/>
</CarouselView.ItemsLayout>
解决
除了去掉报错代码,还有一个就是把HeightRequest和PeekAreaInsets属性一起去掉 但这个好像会导致新的ui问题
处理Bug的具体步骤
- 重现BUG
- 确定发生BUG的过程时都做了哪些动作
- 桌面检查:把自己的脑子作为CPU,运行从开始操作到出现BUG的操作、处理的数据,分析出现问题的原因
- 调试:确定问题出现的原因
- 确定解决方案
- 修复BUG
- 回归测试:确定已BUG已修复并没引入新问题
没有粉丝,没有评论,甚至连读者都没有。因为自己写的烂,因为自己水平有限,所以自己的作品一经发出就石沉大海了,得不到任何的回信,就好像自己写的东西是给自己看的。自己的作品怎么看都好像不够完美,全身的毛病,所以读者不喜欢也很正常对吧!
其实最让我开心的是有些读者们夸我文笔不错,或许是有人第一次这样夸我的缘故吧!又或许是我写的东西没什么人认可,我感受到了一种前所未有的激动,对于未来的憧憬,对自己写下去的动力。
因为有你们,我的写作之路才不孤独,因为有你们,我才能坚持到现在,如果有一天我真的写出圈了,或许我们可以整个交流会之类的,到时候促膝长谈。
“书山有路勤为径,学海无涯苦作舟。”写作苦是苦了点,整得我差点就想放弃了,不过还好有你们。我也不急着成功,因为没有个几十年如一日的坚持,哪能轻易成功?
茫茫文海无人意,天下有君识吾心。文海很孤独,但是有诸君,便足以令我至千里。
更多推荐



所有评论(0)