分组 Observable CollectionView 延迟加载不会在 iOS 上触发

问题描述 投票:0回答:1

我的 .NET MAUI 应用程序中有一个包含按类型分组的任务项的 CollectionView,当满足 ItemThreshold 时会触发按需加载。此行为在 Android 上运行良好,但在 iOS 上似乎不会触发。下面是我的代码:

.xaml 集合视图:

<CollectionView  Margin="5,0,5,0" 
                             SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                             SelectionChangedCommand="{Binding ItemSelectCommand}"    
                             SelectionMode="Single"
                             ItemsSource="{Binding TaskList}"
                             ItemTemplate="{StaticResource TaskSelector}"
                             EmptyView="No Tasks to display"
                             IsGrouped="True"
                             RemainingItemsThreshold="{Binding ItemThreshold}"
                             RemainingItemsThresholdReachedCommand="{Binding LoadMoreDataCommand}">
                    <CollectionView.ItemsLayout>
                        <LinearItemsLayout Orientation="Vertical"
                                       ItemSpacing="2" />
                    </CollectionView.ItemsLayout>
                    <CollectionView.GroupHeaderTemplate>
                        <DataTemplate>
                            <Label Text="{Binding Type}" FontSize="18" FontAttributes="Bold" />
                        </DataTemplate>
                    </CollectionView.GroupHeaderTemplate>
                    <CollectionView.Footer>
                        <StackLayout>
                            <ActivityIndicator IsRunning="True" IsVisible="{Binding IsLoading}" HeightRequest="40" WidthRequest="40" HorizontalOptions="Center" />
                        </StackLayout>
                    </CollectionView.Footer>
                </CollectionView>

如上所示,当达到 ItemThreshold 时,应在滚动到现有列表中的最后几个项目时触发 LoadMoreData 命令。关联的 ViewModel 如下:

.cs

        [RelayCommand]
        private async Task Refresh()
        {
            try
            {
                page = 1;

                (List<TaskListModel> taskList, _) = await restAPIService.GetTaskList(page);

                TaskList.Clear();
                AppendToCollection(taskList);

            }
            catch (Exception ex)
            {
                // catch case
            }
            finally
            {
                ItemThreshold = 0;
            }
        }

        [RelayCommand]
        private async Task LoadMoreData()
        {
            try
            {
                page++;

                (List<TaskListModel> taskList, _) = await restAPIService.GetTaskList(page);

                if (taskList.Count > 0)
                    AppendToCollection(taskList);
                else
                    ItemThreshold = -1;
            }
            catch (Exception ex)
            {
                // catch case
            }
        }

上面的代码在 Android 上运行良好,在列表末尾正确调用了

LoadMoreData
方法。然而,对于 iOS,这个方法永远不会被调用,因此我们的延迟加载不起作用。

感谢任何帮助:)!

我们知道这可能是 iOS 平台 MAUI 分组 CollectionView 的现有错误:

Grouped CollectionView 延迟加载在 iOS 和 Windows 上不会触发 [RemainingItemsThresholdReached] · 问题 #10078 · dotnet/maui · GitHub

https://github.com/dotnet/maui/issues/10078

我们正在积极尝试寻找解决此问题的方法

.net maui observablecollection
1个回答
0
投票

结束,我们将继续使用@Peter 向我们提供的存储库作为目前的解决方法。

© www.soinside.com 2019 - 2024. All rights reserved.