Xamarin.forms: [错误] [iOS]无法访问已处置的对象。 对象名称:'GroupableItemsViewController`1

创建于 2019-10-30  ·  91评论  ·  资料来源: xamarin/Xamarin.Forms

描述

通过标题弹出窗口导航后,带有标题的集合视图会导致崩溃。
该错误仅适用于iOS。 在Android上运行正常。

如果使用标签页,该应用程序将不会崩溃。

重现步骤

  1. 开启应用程式
  2. 使用外壳弹出按钮导航到页面2
  3. 使用外壳弹出按钮导航回到页面1

->该应用程序将崩溃

预期行为

不崩溃。

实际行为

抛出:

System.ObjectDisposedException:'无法访问已处置的对象。
对象名称:“ GroupableItemsViewController`1”。
并崩溃。

基本信息

  • 有问题的版本:4.3.0.947036、4.3.0.908675,...,4.4.0.991265
  • 最后一个好的版本:4.2.0.910310
  • IDE:Visual Studio 2019
  • 平台目标框架:

    • iOS:13.1、13.2(可能还有其他版本)

复制链接

BugExample.zip

collectionview high high impact iOS 🍎 bug

最有用的评论

我找到了解决此错误的方法。 我为Collectionview创建了一个自定义渲染器,并覆盖了Dispose方法。
这是自定义渲染器代码:

[程序集:ExportRenderer(typeof(CollectionView),typeof(CustomCollectionViewRenderer))]
命名空间Project.iOS.Renderers
{
公共类CustomCollectionViewRenderer:CollectionViewRenderer
{
受保护的重写void Dispose(布尔处置)
{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(处置);
}
}
}

所有91条评论

有任何解决方法的想法吗?

TabBar相同的行为。 是否正在进行任何调查?

AppShell.xaml



<!-- Your Pages -->
<TabBar Route="main">
    <Tab Title="Computers" Icon="computers.png" Route="computers">
        <ShellContent ContentTemplate="{DataTemplate computer:ComputersRootPage}" 
                      Title="Root"
                      Route="root"
                      />
    </Tab>
    <Tab Title="Favorites" Icon="favorites.png">
        <ShellContent ContentTemplate="{DataTemplate local:FavoritesPage}" />
    </Tab>
    <Tab Title="Active" Icon="active.png">
        <ShellContent ContentTemplate="{DataTemplate local:ActivePage}" />
    </Tab>
    <Tab Title="Users" Icon="users.png">
        <ShellContent ContentTemplate="{DataTemplate local:UsersPage}" />
    </Tab>
    <Tab Title="Account" Icon="account.png">
        <ShellContent ContentTemplate="{DataTemplate local:AccountPage}" />
    </Tab>
</TabBar>

调试日志

[UICollectionView]无效的更新:第0节中的项目数无效。更新(1)之后现有节中包含的项目数必须等于更新(1)前该节中包含的项目数,再加上或减去从该部分插入或删除的项目数(插入1,删除0),再加上或减去移入或移出该部分的项目数(移入0,移出0)。 -将执行reloadData。 UICollectionView实例:; 层=; contentOffset:{0,-100}; contentSize:{414,45}; AdjustedContentInset:{100,0,0,0}; 布局:; 数据源:>; currentUpdate:[UICollectionViewUpdate-0x7fe2e5e1
c620:旧:项目:<(
“ I(0,0)”
)>]

异常消息

无法访问已处置的对象。
对象名称:GroupableItemsViewController

我刚从一个已经工作了一个月的应用程序修订版本中得到了同样的错误。

在iOS 12.4.1上发生。 来自AppCenter的报告,因此详细信息有限,我无法复制它。 大多数人似乎从未遇到过。

@BioTurboNick您使用哪个版本的Xamarin Forms? 因为您的问题看起来像其他问题。
上面的错误很容易重现,并且每次在页面之间切换时都会发生。

嗯,也许是这样。 我在4.2.0.848062上。 不过,到目前为止,我从未见过GroupableItemsViewController中的ObjectDisposedException。

我在4.2.0.9上测试了此错误...并且工作正常。 可能这是其他吗?

关于XF SDK版本:4.3.0.947036(最新稳定版)

我提出了一个新问题,因为它与之相关,但发生在TabBar上: https :

同样的问题,但没有分组。 在表格版本4.3中

我在页脚的集合视图中遇到问题。 删除页脚似乎已解决了问题。

在4.4.0.991265上仍然出现此问题,我的CollectionView中没有页眉或页脚,并且仍然崩溃。

Untitled

我通过一个简单的(我认为)集合视图得到了这个错误,我使用的是Xamarin Forms 4.4.0.991265,带有一个listview可以正常工作

  <CollectionView Grid.Row="0" ItemsSource="{Binding Currencies}" IsGrouped="False">
                <CollectionView.ItemsLayout>
                   <GridItemsLayout Orientation="Horizontal" />
                </CollectionView.ItemsLayout>
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid Padding="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="100" />
                                <RowDefinition Height="100" />
                            </Grid.RowDefinitions>
                            <Label Grid.Row="0" 
                                   Text="{Binding CCY}" 
                                   FontAttributes="Bold"
                                   FontFamily="AppleSDGothicNeo-UltraLight" 
                                   />
                            <Label Grid.Row="1"
                                   FontFamily="AppleSDGothicNeo-UltraLight" 

                                   TextColor="{Binding Path=Amount, Converter={StaticResource ValueToColorConverter}}"
                                   Text="{Binding ., Converter={StaticResource CurrencyConverter}}"

                                    />
                        </Grid>

                    </DataTemplate>
                </CollectionView.ItemTemplate>
        </CollectionView>

它是第一次渲染,但是当我执行“热重装”时,它会中断:

System.ObjectDisposedException:无法访问已处置的对象。
对象名:“GroupableItemsViewController 1'. at Foundation.NSObject.get_SuperHandle () [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.2.0.42/src/Xamarin.iOS/Foundation/NSObject2.cs:449 at UIKit.UIViewController.get_IsViewLoaded () [0x00023] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.2.0.42/src/Xamarin.iOS/UIViewController.g.cs:2075 at Xamarin.Forms.Platform.iOS.ObservableItemsSource.NotLoadedYet () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:142 at Xamarin.Forms.Platform.iOS.ObservableItemsSource.Add (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x0000d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:147 at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00023] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:100 at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs(object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) at System.Collections.ObjectModel.ObservableCollection 1 T] .OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs E)[0x00018]在/用户/助洗剂/詹金斯/工作区/ xamarin-macios / xamarin-macios /外部/ mono / external / corefx / src / System.ObjectModel / src / System / Collections / ObjectModel / ObservableCollection.cs:263
在System.Collections.ObjectModel.ObservableCollection 1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:338 at System.Collections.ObjectModel.ObservableCollection 1 [T] .InsertItem(System.Int32索引,T项)[0x0001a]在/ Users / builder / jenkins / workspace / xamarin-macios / xamarin-macios /外部/单/外部/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:196
在System.Collections.ObjectModel.Collection`1 [T] ./ Users / builder / jenkins / workspace / xamarin-macios / xamarin-macios / external / mono / external / corefx / src /中添加(T项)[0x00020] Common / src / CoreLib / System / Collections / ObjectModel / Collection.cs:71
在/Users/chris/Projects/O/ViewModels/CashSummaryViewModel.cs:43中的O.ViewModels.CashSummaryViewModel.ExecueLoadItemsCommand(System.Boolean ForceRefresh)[0x00103]
2019年

更新到4.4.0.991265之后,我再次遇到了这个问题-即使是在没有页眉或页脚的集合视图上。 :(

请紧急解决此问题。 我也有这个问题。 因此,无法在生产中使用外壳。 应该标记为关键。

重现步骤
开启应用程式
使用外壳弹出按钮导航到页面2
使用外壳弹出按钮导航回到页面1
->该应用程序将崩溃

同样的问题。 为什么还没有解决?

@jsiemens说了什么👆

在带有或不带有页眉和页脚的collectionview中,我也面临着这个问题。 使用Xamarin.Forms 4.4.0.991640

@hartez谢谢。 这是一个严重的错误,使Shell无法在iOS上使用。

我遇到了同样的问题,无法发布有问题的应用...。请修复该问题!

这里同样的问题。

这里同样的问题

4.4.0.991640上的相同问题,没有外壳,没有标题和页脚。

使用CarouselView也会发生,我想它在引擎盖下有相同的东西

来吧,Xamarin团队...在生产中出现崩溃的错误5个月真的可以接受吗?

@PureWeen @hartez @samhouts

在4.5之前从未出现过此错误。
更新到4.5后,此错误会出现在CollectionView(没有Shell)上。

这里与热重装同样的问题:
就我而言,一个ListView

风景:
`


    <StackLayout>
        <ListView x:Name="LvAbwesenheiten" BackgroundColor="Transparent" 
                  HasUnevenRows="True" 
                  ItemTemplate="{StaticResource AbwesenheitTemplateSelector}"
                  SeparatorVisibility="None"
                  />
  </StackLayout>

`

ViewCell(模板):
` xmlns:x =“ http://schemas.microsoft.com/winfx/2009/xaml”
x:Class =“ DATAflor.Team.DFViews.Urlaub.CustomCells.AbwesenheitCell”>

    <StackLayout x:Name="StackLayoutMain" 
                 Orientation="Horizontal" 
                 HorizontalOptions="Fill" 
                 Padding="10" 

                 >
        <StackLayout.Resources>
            <Style x:Key="LabelStyleZeitraum" TargetType="Label">
                <Setter Property="TextColor" Value="{DynamicResource TextOnBackgroundColor}"/>
                <Setter Property="FontSize" Value="15"/>
            </Style>
            <Style x:Key="LabelStyleText" TargetType="Label">
                <Setter Property="TextColor" Value="{DynamicResource TextOnBackgroundColor}"/>
                <Setter Property="FontSize" Value="13"/>
            </Style>
        </StackLayout.Resources>
        <!--BackgroundColor="{Binding Path=BackgroundColor}"-->

        <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">

            <StackLayout Orientation="Horizontal">
                <Label Text="{Binding Von, StringFormat='{0:dd.MM.yyyy}'}" Style="{StaticResource LabelStyleZeitraum}" />
                <Label Text=" - " Style="{StaticResource LabelStyleZeitraum}"/>
                <Label Text="{Binding Bis, StringFormat='{0:dd.MM.yyyy}'}" Style="{StaticResource LabelStyleZeitraum}"/>
            </StackLayout>

            <Label Text="{Binding Text}" 
                   Style="{StaticResource LabelStyleText}"
                   />


        </StackLayout>



    </StackLayout>
</ViewCell.View>

`

每当我在模板中更改某些内容时,点击保存以启动热重装,就会发生错误(Simulator中的iOS 13;真实设备上的iOS 12)

并不是每个Listview / Template都发生这种情况,我也不知道区别是什么或如何解决...直到现在,它仅在Hot-Reload中发生,这很烦人但并不关键-但当我读到其中的一些内容时你在正常运行时有这个我有点害怕...

这是一个堆栈跟踪:

`无法访问已处置的对象。
对象名称:“ DefaultRenderer”。

在/Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.3.0/src/Xamarin.iOS/Foundation/NSObject2.cs:449中的Foundation.NSObject.get_SuperHandle()[0x00012]
在/Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.3.0/src/Xamarin.iOS/UIView.g.cs:3684中的UIKit.UIView.set_Frame(CoreGraphics.CGRect值)[0x00024]
在Xamarin.Forms.Platform.iOS.ViewCellRenderer + ViewTableCell.LayoutSubviews()在D:\ a \ 1 \ s \ Xamarin.Forms.Platform.iOS \ Cells \ ViewCellRenderer.cs:103中的[0x000a5]
在(包装器托管到本地)ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_Int64(intptr,intptr,intptr,long)
在/Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.3.0/src/Xamarin.iOS/UITableView.g中的UIKit.UITableView.ReloadRows(Foundation.NSIndexPath [] atIndexPaths,UIKit.UITableViewRowAnimation withRowAnimation)[0x0002a]中。 cs:824
在Xamarin.Forms.Platform.iOS.CellRenderer + <> c__DisplayClass8_0中。D:\ a \ 1 \ s \ Xamarin.Forms.Platform.iOS \ Cells \ CellRenderer.cs:106中的b__0(System.Object发送者,System.EventArgs e)[0x00032]
位于D:\ a \ 1 \ s \ Xamarin.Forms.Core \ Cells \ Cell.cs:234中的Xamarin.Forms.Cell.OnForceUpdateSizeRequested()[0x00076]

我的应用程式中也有这个问题。 删除相应页面中具有高度为100的不可见boxview的collectionview的页脚(只需在视图底部添加一些空间)即可解决此问题。
还有另一件事效果很好:我的shellpage中有多个flyoutitem定义。 如果我只有一个flyoutitem定义,则不会出现此问题。 因此,如果您可以设法设计shell弹出窗口,以便每个shell内容都在一个flyoutitem中,则可以解决此问题。

@Genfood在您的示例项目上,该问题是ItemsPage中collectionview的标题。 删除它可以解决问题,但无论设置或不设置标题都不会崩溃。 如上所述,您可以做的另一件事是将所有flyoutitem合并为一个。 那么它也会工作。

这个讨厌的错误需要修复

@samhouts该修复程序何时发布?

@samhouts我刚刚尝试了该版本,问题仍然存在。

System.ObjectDisposedException
Message =无法访问已处置的对象。
对象名称:“ WkWebViewRenderer”。

我也面临着同样的问题

@samhouts这不是固定的。

我在新发布的4.6稳定版中对其进行了测试。 它似乎是固定的。 🎉
至少我附加到此问题的错误示例现在可以正常工作。

@samhouts如果您具有CollectionView,但已修复,但如果您具有WebView,则不会被修复。 那还是坏了。 大概还有几个。

@samhouts我刚刚尝试了该版本,问题仍然存在。

System.ObjectDisposedException
Message =无法访问已处置的对象。
对象名称:“ WkWebViewRenderer”。

@ g4mb10r与原始发布的问题相比,来自不同控件的错误不同。 ObjectDisposedExceptions可能有很多原因。

请用您的信息(这是WkWebviewRenderer)打开一个新问题,并包括您拥有的其他信息(堆栈跟踪,如果可能的话是一个repro项目)。

@samhouts我在v1.6中的CollectionViews上仍然遇到此问题。 这是跟踪:

在/Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/Foundation/NSObject2.cs:449中的Foundation.NSObject.get_SuperHandle()[0x00012]

在/Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UIView.g.cs:3685中的UIKit.UIView.set_Frame(CoreGraphics.CGRect值)[0x00024]

在D:\ a \ 1 \ s \ Xamarin.Forms.Platform.iOS \ CollectionView \ ItemsViewController.cs:318中的Xamarin.Forms.Platform.iOS.ItemsViewController`1 [TItemsView] .LayoutEmptyView()[0x0000f]

在Xamarin.Forms.Platform.iOS.ItemsViewController`1 [TItemsView] .ViewWillLayoutSubviews()[0x00046]在D:\ a \ 1 \ s \ Xamarin.Forms.Platform.iOS \ CollectionView \ ItemsViewController.cs:161中

位于Xamarin.Forms.Platform.iOS.StructuredItemsViewController`1 [TItemsView] .ViewWillLayoutSubviews()[0x00000]在D:\ a \ 1 \ s \ Xamarin.Forms.Platform.iOS \ CollectionView \ StructuredItemsViewController.cs:78

在(包装器托管到本地)UIKit.UIApplication.UIApplicationMain(int,string [],intptr,intptr)

在/Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS中的UIKit.UIApplication.Main(System.String [] args,System.IntPtr主体,System.IntPtr委托)[0x00005] /UIKit/UIApplication.cs:86

在/Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS中的UIKit.UIApplication.Main(System.String [] args,System.StringPrincipalClassName,System.String委托ClassName)[0x0000e] /UIKit/UIApplication.cs:65

在C:\ Code \ Logbook \ Logbook \ Logbook.iOS \ Main.cs:17中的Logbook.iOS.Application.Main(System.String [] args)[0x00001]

我一直无法查明导致问题的确切原因,但是在使用Shell的flyoutitem中的多个选项卡中都有CollectionViews。 每个CollectionView使用组标题。

用CollectionView加载选项卡很好,然后第二个也可以。 当我尝试导航回先前查看的崩溃时,发生崩溃。

我正在尝试在一个示例项目中复制它,但到目前为止还无法完成。 另外,我在Android上没有任何问题。

编辑

我已经找到了原因,因此我打开了一个新的#10953问题。 不确定是否与原始海报的发行有关。

这在iOS的v4.7.0.1080中仍然没有解决。 Android很好。

3x不同页面上的3x CollectionViews,没有页眉或页脚。 不使用Shell,仅使用普通的ContentPages。

是否热加载,都没有关系。 初次查看收藏的人口就可以了。 刷新会导致崩溃。 这可能是collectionview最简单的实现。

当清除基础ObservableCollection然后重新填充时,所有中断都以完全相同的方式中断。

我不敢相信,将近9个月后,这种情况仍然令人感到厌烦。

如果这样做对关闭但未修复的其他人有帮助,我会注意到,如果在清除和重新填充之间引入非常短的延迟(> 100ms),这似乎很有帮助。 我不喜欢引入延迟来“修复”问题。

如果您尝试使用其他方法清除它,例如while observablecollection.count > 0 do observablecollection.removeat(0) (以清除它),然后尝试重新填充得太快,则有时您会从SemaphoreSlim中得到另一个异常:

System.Threading.SemaphoreFullException: Adding the specified count to the semaphore would cause it to exceed its maximum

就像@ wislon☹️一样,可以添加并在iOS v12.4上重现它,但是在v13.5中可以正常工作

更新:

使用Xamarin.Forms 4.6.0.1180此错误在iOS v12.4上不可重现

我仍在运行最新版本的Xamarin.Forms运行IOS 12.4.5

我可以在运行iOS 12.4.1(而不是13.x)和Xamarin.Forms 4.7的情况下对其进行复制。 请再次打开该错误。

@ robintschroeder@ daves1992可以使用BugExample复制吗?

@rmarinho是的,刚刚在运行12.4.5的Iphone 6上进行了测试,并且能够首次使用BugExample进行复制

System.ObjectDisposedException:'无法访问已处置的对象。
对象名称:“ GroupableItemsViewController`1”。

我在iOS 12.2 Simulator上使用4.8进行了测试,并且似乎可以正常工作。

我不好,我忘了更新示例中的Xamarin.Forms。 我更新到4.8,但由于无法复制示例或我的应用,因此……我一直在监视它,因为它隔天都没有复制,我在4.7.X上的使用率为100%

该错误仍然存​​在于xamarin 4.8(iphone 6,ios 12.4.6)

@rkarban你有回购协议吗? 我只是测试过而无法复制。

不幸的是, @ rmarinho回购是私人的,我无法访问
这是堆栈跟踪
NSObject.get_SuperHandle()
UICollectionViewController.get_CollectionView()
ItemsViewController`1 [TItemsView] .GetPrototype()
ItemsViewLayout.DetermineCellSize()
ListViewLayout.ConstrainTo(CoreGraphics.CGSize大小)
ItemsViewLayout.UpdateConstraints(CoreGraphics.CGSize大小)
ItemsViewLayout.InvalidateLayout()
(包装器托管到本地)UIKit.UIApplication.UIApplicationMain(int,string [],intptr,intptr)
UIApplication.Main(System.String []参数,System.IntPtr主体,System.IntPtr委托)
UIApplication.Main(System.String []参数,System.StringPrincipalClassName,System.String委托ClassName)
Application.Main(System.String [] args)

BugExample.zip

@rmarinho我通过稍微改变示例来设法复制了它。

我为设置Items属性添加了100ms的延迟。

iPhone 6
iOS 12.4.5
Xamarin.Forms 4.8

    ObservableCollection<string> items;

    public ObservableCollection<string> Items
    {
        get { return items; }
        set 
        {
            SetProperty(ref items, value);
        }
    }

    public Command LoadItemsCommand { get; set; }

    public ItemsViewModel()
    {
        Title = "Browse";
        _= getItems();
    }

    async Task getItems()
    {
        await Task.Delay(100);
        Items = new ObservableCollection<string>
        {
            "Test",
            "Test",
            "Test",
            "Test",
            "Test",
        };
    }

即使使用Xamarin Forms 4.8,我在ios 12上也遇到相同的问题。 Collectionview在这些设备上崩溃。 我们需要重新打开这个问题。

我找到了解决此错误的方法。 我为Collectionview创建了一个自定义渲染器,并覆盖了Dispose方法。
这是自定义渲染器代码:

[程序集:ExportRenderer(typeof(CollectionView),typeof(CustomCollectionViewRenderer))]
命名空间Project.iOS.Renderers
{
公共类CustomCollectionViewRenderer:CollectionViewRenderer
{
受保护的重写void Dispose(布尔处置)
{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(处置);
}
}
}

我找到了解决此错误的方法。 我为Collectionview创建了一个自定义渲染器,并覆盖了Dispose方法。
这是自定义渲染器代码:

[程序集:ExportRenderer(typeof(CollectionView),typeof(CustomCollectionViewRenderer))]
命名空间Project.iOS.Renderers
{
公共类CustomCollectionViewRenderer:CollectionViewRenderer
{
受保护的重写void Dispose(布尔处置)
{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(处置);
}
}
}

感谢分享。 我会尝试的。 我们还看到有关此问题的大量崩溃。

我找到了解决此错误的方法。 我为Collectionview创建了一个自定义渲染器,并覆盖了Dispose方法。
这是自定义渲染器代码:

[程序集:ExportRenderer(typeof(CollectionView),typeof(CustomCollectionViewRenderer))]
命名空间Project.iOS.Renderers
{
公共类CustomCollectionViewRenderer:CollectionViewRenderer
{
受保护的重写void Dispose(布尔处置)
{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(处置);
}
}
}

有些英雄不戴斗篷

@rmarinho @samhouts我们可以重新打开此错误吗? 我设法使用上面示例的调整版本再次进行复制,似乎更多的人遇到了这个问题。

即使使用最新的表格,我也遇到同样的问题。 没有外壳,没有页眉或页脚。

我遇到了同样的问题,但是在运行iOS 12.4.8的iPad和运行iOS 12.4.1的iPhone上使用了ListView,但是在iOS 13的设备上却没有。我在以iOS 13.4为目标的Xamarin Forms 4.7 SR5上。

Xamarin Exception Stack:
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GroupableItemsViewController`1'.
  at Foundation.NSObject.get_SuperHandle () <0x101941484 + 0x0009c> in <698888335fd24bdca1317448cda6f409#1ffb13f9a443e65aad81d66c194bad70>:0
  at UIKit.UICollectionViewController.get_CollectionView () <0x10191f038 + 0x0002f> in <698888335fd24bdca1317448cda6f409#1ffb13f9a443e65aad81d66c194bad70>:0
  at Xamarin.Forms.Platform.iOS.ItemsViewController`1[TItemsView].GetPrototype () <0x101e787f0 + 0x00113> in <c02bcffd65214bdd87ba2c816440c864#1ffb13f9a443e65aad81d66c194bad70>:0
  at Xamarin.Forms.Platform.iOS.ItemsViewLayout.DetermineCellSize () <0x101e7fde0 + 0x000a3> in <c02bcffd65214bdd87ba2c816440c864#1ffb13f9a443e65aad81d66c194bad70>:0
  at Xamarin.Forms.Platform.iOS.ListViewLayout.ConstrainTo (CoreGraphics.CGSize size) <0x101e80efc + 0x00037> in <c02bcffd65214bdd87ba2c816440c864#1ffb13f9a443e65aad81d66c194bad70>:0
  at Xamarin.Forms.Platform.iOS.ItemsViewLayout.UpdateConstraints (CoreGraphics.CGSize size) <0x101e7f944 + 0x0006b> in <c02bcffd65214bdd87ba2c816440c864#1ffb13f9a443e65aad81d66c194bad70>:0
  at Xamarin.Forms.Platform.iOS.ItemsViewLayout.InvalidateLayout () <0x101e80ac0 + 0x00043> in <c02bcffd65214bdd87ba2c816440c864#1ffb13f9a443e65aad81d66c194bad70>:0
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) <0x1018fa618 + 0x0003f> in <698888335fd24bdca1317448cda6f409#1ffb13f9a443e65aad81d66c194bad70>:0
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) <0x1018fa570 + 0x00053> in <698888335fd24bdca1317448cda6f409#1ffb13f9a443e65aad81d66c194bad70>:0
  at FieldEdge.Mobile.Tablet.iOS.Application.Main (System.String[] args) <0x10054cbf8 + 0x00033> in <ca210f5f974b45669b487b30759435fc#1ffb13f9a443e65aad81d66c194bad70>:0

ListView有任何解决方法吗?

@ rd09 ListView不使用GroupableItemsViewController。 您确定没有使用CollectionView吗?

@ rd09 ListView不使用GroupableItemsViewController。 您确定没有使用CollectionView吗?

谢谢您的注意,您是正确的。 我以某种方式假定了这一点,但是在检查了源代码并进行了验证之后,我决定应用@ l0gaw发布并起作用的解决方法。

使用@ l0gaw解决方法修复了我之前看到的崩溃,但是现在我又遇到了另一个崩溃,但异常相同但堆栈跟踪不同:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GroupableItemsViewController`1'.
  at Foundation.NSObject.get_SuperHandle () <0x101d8f3c0 + 0x0009c> in <698888335fd24bdca1317448cda6f409#b6c34173f62d398ef7bfb32c87027461>:0
  at UIKit.UIViewController.get_IsViewLoaded () <0x101d671f4 + 0x0000f> in <698888335fd24bdca1317448cda6f409#b6c34173f62d398ef7bfb32c87027461>:0
  at Xamarin.Forms.Platform.iOS.ObservableItemsSource.ReloadRequired () <0x1022cfc28 + 0x00017> in <f363ad1ddcfd4686ace46d6cfc5b07cf#b6c34173f62d398ef7bfb32c87027461>:0
  at Xamarin.Forms.Platform.iOS.ObservableItemsSource.Remove (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) <0x1022d0e9c + 0x0013b> in <f363ad1ddcfd4686ace46d6cfc5b07cf#b6c34173f62d398ef7bfb32c87027461>:0
  at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) <0x1022d00a8 + 0x001bf> in <f363ad1ddcfd4686ace46d6cfc5b07cf#b6c34173f62d398ef7bfb32c87027461>:0
  at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) <0x1022007b0 + 0x00417> in <f363ad1ddcfd4686ace46d6cfc5b07cf#b6c34173f62d398ef7bfb32c87027461>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) <0x100c355e8 + 0x0005b> in <624bcc4ce53347508a7b8fa821d78da4#b6c34173f62d398ef7bfb32c87027461>:0
  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () <0x101d8d5fc + 0x0002f> in <698888335fd24bdca1317448cda6f409#b6c34173f62d398ef7bfb32c87027461>:0
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) <0x101d48708 + 0x0003f> in <698888335fd24bdca1317448cda6f409#b6c34173f62d398ef7bfb32c87027461>:0
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) <0x101d48660 + 0x00053> in <698888335fd24bdca1317448cda6f409#b6c34173f62d398ef7bfb32c87027461>:0
  at FieldEdge.Mobile.Tablet.iOS.Application.Main (System.String[] args) <0x1009aa488 + 0x00033> in <044acf8dc1f745b3bc6b51b04b6a2bae#b6c34173f62d398ef7bfb32c87027461>:0

我们也仅在iOS 12上看到了这一点,到目前为止还没有找到解决方法。

我在iPad中也有这个错误

  • 赛马林4.7
  • iOS 13.5.1

SIGABRT:无法访问已处置的对象。

NSObject.get_SuperHandle ()
UIViewController.get_NavigationItem ()
NavigationRenderer+<>c__DisplayClass79_0.<SetMasterLeftBarButton>b__0 (UIKit.UIImage icon)
ImageElementManager.ApplyNativeImageAsync (Xamarin.Forms.BindableObject bindable, Xamarin.Forms.BindableProperty imageSourceProperty, System.Action`1[T] onSet, System.Action`1[T] onLoading, System.Threading.CancellationToken cancellationToken)
NavigationRenderer.SetMasterLeftBarButton (UIKit.UIViewController containerController, Xamarin.Forms.MasterDetailPage masterDetailPage)
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state)
NSAsyncSynchronizationContextDispatcher.Apply ()
(wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)

我找到了解决此错误的方法。 我为Collectionview创建了一个自定义渲染器,并覆盖了Dispose方法。
这是自定义渲染器代码:

[程序集:ExportRenderer(typeof(CollectionView),typeof(CustomCollectionViewRenderer))]
命名空间Project.iOS.Renderers
{
公共类CustomCollectionViewRenderer:CollectionViewRenderer
{
受保护的重写void Dispose(布尔处置)
{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(处置);
}
}
}

@ l0gaw是否需要在iOS项目中仅实现CustomRenderer或在主项目中需要其他功能?

@matheuscschenfeld在iOS项目中

也仍然遇到此问题,解决方法不能解决此问题

编辑
我解决了我的问题。 我正在绑定到模型命令而不是viewmodel命令。 在视图模型之间来回切换时,此绑定未更新。 因此,与其在新的viewmodel源上消除集合项,不如从已处置的集合中删除一个项。
更改到视图模型而不是模型的绑定时,不再有问题。

您必须小心使用发布的解决方法,因为将SelectedItem设置为null的行会触发SelectedItem事件,因此,如果您对该属性设置了两种方式的绑定并且未检查null,则会导致异常。 我完全删除了该行,因为我认为该解决方法不是必需的。

@samhouts是否会很快

我猜这可能已在Xamarin.Forms 5.x上修复,或者可能等到MAUI。 我希望是错的

我也在iOS模拟器的Xamarin 4.8上重现了这个问题

@samhouts @hartez许多人仍在报告这个相当大的错误。 该错误的范围太小,无法囊括实际问题。

令人印象深刻的是此问题尚未解决,我也遇到了这个错误,CollectionView在iOS上无法正常工作

@ l0gaw的解决方法曾经可以使用,但是现在不起作用了。 无法确定它是否来自上一次iOS更新,但确实变得很烦人-从简单更新/清除到处崩溃。

@mduchev我也看到了这一点。 它同时在iOS 13和14上发生。对我而言唯一改变的是移至Xamarin.iOS 14.正在尝试查看我现在是否可以解决此问题。

具体来说,这是我现在看到的堆栈:

NSObject.get_SuperHandle ()
UIViewController.get_IsViewLoaded ()
ObservableItemsSource.NotLoadedYet ()
ObservableItemsSource.ReloadRequired ()
ObservableItemsSource.Remove (System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
ObservableItemsSource.CollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
ObservableItemsSource.CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state)
NSAsyncSynchronizationContextDispatcher.Apply ()
(wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)

发布建议的解决方法后,我现在在App Center中看到以下异常: System.IndexOutOfRangeException:IItemsViewSource为空

Xamarin.Forms.Platform.iOS
EmptySource.GetIndexForItem (System.Object item)
Xamarin.Forms.Platform.iOS
ItemsViewController`1[TItemsView].GetIndexForItem (System.Object item)
Xamarin.Forms.Platform.iOS
SelectableItemsViewController`1[TItemsView].SelectItem (System.Object selectedItem)
Xamarin.Forms.Platform.iOS
SelectableItemsViewController`1[TItemsView].UpdateNativeSelection ()
Xamarin.Forms.Platform.iOS
SelectableItemsViewRenderer`2[TItemsView,TViewController].UpdateNativeSelection ()
Xamarin.Forms.Platform.iOS
SelectableItemsViewRenderer`2[TItemsView,TViewController].UpdateItemsSource ()
Xamarin.Forms.Platform.iOS
ItemsViewRenderer`2[TItemsView,TViewController].OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs changedProperty)
Xamarin.Forms.Platform.iOS
StructuredItemsViewRenderer`2[TItemsView,TViewController].OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs changedProperty)
Xamarin.Forms.Platform.iOS
SelectableItemsViewRenderer`2[TItemsView,TViewController].OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs changedProperty)
Xamarin.Forms.Platform.iOS
GroupableItemsViewRenderer`2[TItemsView,TViewController].OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs changedProperty)
(wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
Xamarin.Forms
BindableObject.OnPropertyChanged (System.String propertyName)
Xamarin.Forms
Element.OnPropertyChanged (System.String propertyName)
Xamarin.Forms
BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
Xamarin.Forms
BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
Xamarin.Forms
BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess)
Xamarin.Forms
ItemsView.set_ItemsSource (System.Collections.IEnumerable value)
FieldEdge.Mobile.iOS.CustomRenderers
CustomCollectionViewRenderer.Dispose (System.Boolean disposing)
Foundation
NSObject.Dispose ()
Xamarin.Forms.Platform.iOS
VisualElementPackager.Dispose (System.Boolean disposing)
Xamarin.Forms.Platform.iOS
VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing)
Foundation
NSObject.Dispose ()
Xamarin.Forms.Platform.iOS
VisualElementPackager.Dispose (System.Boolean disposing)
Xamarin.Forms.Platform.iOS
VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing)
Foundation
NSObject.Dispose ()
Xamarin.Forms.Platform.iOS
VisualElementPackager.Dispose (System.Boolean disposing)
Xamarin.Forms.Platform.iOS
VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing)
Foundation
NSObject.Dispose ()
Xamarin.Forms.Platform.iOS
VisualElementPackager.Dispose (System.Boolean disposing)
Xamarin.Forms.Platform.iOS
VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing)
Foundation
NSObject.Dispose ()
Xamarin.Forms.Platform.iOS
DisposeHelpers.DisposeModalAndChildRenderers (Xamarin.Forms.Element view)
Xamarin.Forms.Platform.iOS.Platform.Xamarin.Forms
INavigation.PopModalAsync (System.Boolean animated)
Xamarin.Forms
Application+NavigationImpl.OnPopModal (System.Boolean animated)
FieldEdge.Mobile.Shared.MVVMFramework
NavigationService+<>c__DisplayClass8_0.<CloseModal>b__0 ()

您要从收藏夹中移除物品吗? 如果是这样,那么您可能遇到了另一个已报告的问题(我也在不断遇到此问题) -https://github.com/xamarin/Xamarin.Forms/issues/9632。 如果不是这样,那么我想,如上所述,很遗憾,该解决方法在所有情况下均无法正常工作。

我能够重新创建我发布的上一个问题。 当我导航到具有CollectionView的屏幕时,可以通过添加或删除项目来对其进行修改,然后关闭屏幕,将引发此异常。 如果我转到同一屏幕并且不修改CollectionView,则退出屏幕不会引发异常。 但是,该解决方法仍然对我有用,因为清除CollectionView会崩溃,因此我确实必须重构某些区域。 因此,解决方法肯定会引入新问题。 我认为目前最安全的选择是不使用CollectionViews。

我有同样的问题。
方案是

  • 创建轮播视图
  • 在carouselview模板中使用collectionview
  • 例如,点击轮播项目和收集项目; 使它们的状态发生变化-变得陈旧
  • 尝试更新一些XAML零件,并检查是否通过热重装更新了视图
  • 单击carouselview-再次查看集合项

在这一点上,错误引发了我的经验。

  • 它发生在使用iOS模拟器的调试模式下
  • 但是我无法在发布模式下部署的iPhone设备上重现它。
  • 对于我来说,只有在调试模式下才会出现错误。

如果有人可以为示例项目提供最新的Xamarin软件包,则修复起来会容易得多。 当这种情况不断发生时,我似乎无法查明确切的情况。 如果有人可以,请提供一个描述问题的演示项目,以便可以快速解决。

@mduchev您看到@ daves1992的评论吗?

https://github.com/xamarin/Xamarin.Forms/issues/8308#issuecomment -672028716

只是问一下,因为它有点被大量评论淹没了。 它不会为您重现问题吗?

@lafritay不幸的是,没有。 我可以在模拟器和设备上启动项目,而没有任何问题。 在页面之间导航似乎也不会触发异常。

@lafritay不幸的是,没有。 我可以在模拟器和设备上启动项目,而没有任何问题。 在页面之间导航似乎也不会触发异常。

哪个版本的IOS?

我设法在12.4.1上复制了它,但是我不认为它会在更高版本上复制。

如果有人可以为示例项目提供最新的Xamarin软件包,则修复起来会容易得多。 当这种情况不断发生时,我似乎无法查明确切的情况。 如果有人可以,请提供一个描述问题的演示项目,以便可以快速解决。

您必须在iOS 12上才能重新创建。

@ rd09不正确。 我在iOS 13设备上看到了相同的错误,现在在iOS 14设备上再次看到了此错误。 不幸的是,示例项目似乎并没有重现问题,因此我认为它仍然以其他形式存在。

再现+解决方案: https :

没有解决方法。

@mduchev @ rd09我能够得到一个简单的再现:

Bugs.zip

加载应用程序后,等待项目加载。 然后执行以下操作:

  1. 使用菜单导航到“关于”页面
  2. 导航回到项目页面(应该为空白)
  3. 使用“拉动刷新”刷新页面。 当项目完成加载时,应该发生异常。

做到这一点的关键是ItemsPage.xaml.cs中的这一行

        protected override void OnDisappearing()
        {
            ItemsCollectionView.ItemsSource = null;
            base.OnDisappearing();
        }

问题在于,如果CollectionView.ItemsSource曾经被更新过,则包含原始值的ItemsViewSource永远不会被丢弃。 因此,它保留其CollectionChanged处理程序并对更改做出反应。 如果集合在离开页面后得到更新(例如,由于网络通话缓慢),则错误的ItemsViewSource访问已处置的ItemsViewController

我相信问题在于此文件中的UpdateItemsSource方法: https : ItemsSource持有的值。

这似乎是由以下事实证实的:它的Android对应对象确实处理了该对象(请参阅此文件中的UpdateItemsSource :https://github.com/xamarin/Xamarin.Forms/blob/79cc0f49fe90a59f02aa0490072b449ccdad4a27/Xamarin.Forms .Platform.Android / CollectionView / ItemsViewAdapter.cs)

而且,我认为导致这种情况继续发生的主要原因之一是,在调用dispose时,许多人使用的解决方法使ItemsSource无效。

@lafritay Im正在使用此替代方法,该方法似乎可以在短期测试中起作用。 当收集源正确更改时,这并不能完全解决处置问题,但是可以防止崩溃

```
使用Example.Controls;
使用Example.iOS.Renderers;
使用Xamarin.Forms;
使用Xamarin.Forms.Platform.iOS;

[程序集:ExportRenderer(typeof(ExtendedCollectionView),typeof(ExtendedCollectionViewRender))]
命名空间Example.iOS.Renderers
{
公共类ExtendedCollectionViewRender:CollectionViewRenderer
{
受保护的重写GroupableItemsViewControllerCreateController(GroupableItemsView itemsView,ItemsViewLayout布局)
{
返回新的CustomGroupableItemsViewController(itemsView,布局);
}
}
}

使用Xamarin.Forms;
使用Xamarin.Forms.Platform.iOS;

命名空间Example.iOS.Renderers
{
公共类CustomGroupableItemsViewController:GroupableItemsViewController
其中TItemsView:GroupableItemsView
{
公共CustomGroupableItemsViewController(TItemsView selectableItemsView,ItemsViewLayout布局):base(selectableItemsView,布局)
{
}

    protected override void Dispose(bool disposing)
    {
        base.Dispose(disposing);
        ItemsSource = new EmptySource();
    }
}

}

使用系统;
使用基金会;
使用Xamarin.Forms.Platform.iOS;

命名空间Example.iOS.Renderers
{
内部类EmptySource:IItemsViewSource
{
public int GroupCount => 0;

    public int ItemCount => 0;

    public bool Loop { get ; set; }

    public int LoopCount => 0;

    public object this[NSIndexPath indexPath] => throw new IndexOutOfRangeException("IItemsViewSource is empty");

    public int ItemCountInGroup(nint group) => 0;

    public object Group(NSIndexPath indexPath)
    {
        throw new IndexOutOfRangeException("IItemsViewSource is empty");
    }

    public NSIndexPath GetIndexForItem(object item)
    {
        throw new IndexOutOfRangeException("IItemsViewSource is empty");
    }

    public void Dispose()
    {
    }
}

}

@jormenjanssen这是我的完整解决方法:

using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

namespace myTIPreport.iOS
{
    /// <summary>
    /// Needed because of this bug: https://github.com/xamarin/xamarin.forms/issues/10842. And this bug:
    /// https://github.com/xamarin/Xamarin.Forms/issues/9691
    /// </summary>
    internal sealed class DefaultCollectionItemsViewController : GroupableItemsViewController<GroupableItemsView>
    {
        public DefaultCollectionItemsViewController(GroupableItemsView itemsView, ItemsViewLayout itemsLayout)
            : base(itemsView, itemsLayout)
        {
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Needed because of this bug: https://github.com/xamarin/Xamarin.Forms/issues/9691
            CollectionView.ContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.Automatic;
        }

        public override void UpdateItemsSource()
        {
            // Needed because of this bug: https://github.com/xamarin/Xamarin.Forms/issues/8308#issuecomment-710138958
            ItemsSource?.Dispose();
            base.UpdateItemsSource();
        }

        protected override UICollectionViewDelegateFlowLayout CreateDelegator() =>
            new DefaultCollectionItemsViewDelegator(ItemsViewLayout, this);
    }
}
using CoreGraphics;
using Foundation;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

namespace myTIPreport.iOS
{
    /// <summary>
    /// Only needed because of this bug: https://github.com/xamarin/xamarin.forms/issues/10842
    /// </summary>
    internal sealed class DefaultCollectionItemsViewDelegator : SelectableItemsViewDelegator<GroupableItemsView, DefaultCollectionItemsViewController>
    {
        public DefaultCollectionItemsViewDelegator(
            ItemsViewLayout itemsLayout,
            DefaultCollectionItemsViewController itemsController)
            : base(itemsLayout, itemsController)
        {
        }

        /// <summary>
        /// Per default this method returns the Estimated size when its not overriden. This method is called
        /// before the rendering process and sizes the cell correctly before it is displayed in the
        /// CollectionView. Calling the base implementation of this method will throw an exception when
        /// overriding the method.
        /// </summary>
        public override CGSize GetSizeForItem(
            UICollectionView collectionView,
            UICollectionViewLayout layout,
            NSIndexPath indexPath)
        {
            // CellForItem() is not reliable here because when the cell at indexPath is not visible it will
            // return null.
            UICollectionViewCell cell = collectionView.CellForItem(indexPath);
            if (cell is ItemsViewCell itemsViewCell)
            {
                // Get the real cell size.
                return itemsViewCell.Measure();
            }
            else
            {
                // This is basically a fallback when CellForItem() returns null.
                return ItemsViewLayout.EstimatedItemSize;
            }
        }
    }
}

using myTIPreport.iOS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(CollectionView), typeof(DefaultCollectionViewRenderer))]

namespace myTIPreport.iOS
{
    /// <summary>
    /// Reasons for this:
    /// 1. This bug: https://github.com/xamarin/xamarin.forms/issues/10842
    /// 2. This bug: https://github.com/xamarin/Xamarin.Forms/issues/8308
    /// </summary>
    internal class DefaultCollectionViewRenderer : GroupableItemsViewRenderer<GroupableItemsView, DefaultCollectionItemsViewController>
    {
        protected override DefaultCollectionItemsViewController CreateController(
            GroupableItemsView itemsView,
            ItemsViewLayout itemsLayout
        ) => new DefaultCollectionItemsViewController(itemsView, itemsLayout);

        protected override void Dispose(bool disposing)
        {
            // Workaround for this bug: https://github.com/xamarin/Xamarin.Forms/issues/8308
            ItemsView.SelectedItem = null;
            ItemsView.ItemsSource = null;

            base.Dispose(disposing);
        }
    }
}

我找到了解决此错误的方法。 我为Collectionview创建了一个自定义渲染器,并覆盖了Dispose方法。
这是自定义渲染器代码:
[程序集:ExportRenderer(typeof(CollectionView),typeof(CustomCollectionViewRenderer))]
命名空间Project.iOS.Renderers
{
公共类CustomCollectionViewRenderer:CollectionViewRenderer
{
受保护的重写void Dispose(布尔处置)
{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(处置);
}
}
}

@ l0gaw是否需要在iOS项目中仅实现CustomRenderer或在主项目中需要其他功能?

在我的情况下,此解决方法有效。 我确实也删除了“ ItemsView.SelectedItem = null”行,因为在我的情况下,就像@ rd09所说的那样,

我遇到相同的问题,是否有解决方案或解决方法?...这是堆栈跟踪...
我正在使用xamarin形式的最新稳定版本
使用AppShell
发生在iOS 12中
NSObject.get_SuperHandle()
UICollectionViewController.get_CollectionView()
ItemsViewController`1 [TItemsView] .GetPrototype()
ItemsViewLayout.DetermineCellSize()
ListViewLayout.ConstrainTo(CoreGraphics.CGSize大小)
ItemsViewLayout.UpdateConstraints(CoreGraphics.CGSize大小)
ItemsViewLayout.InvalidateLayout()
(包装器托管到本地)UIKit.UIApplication.UIApplicationMain(int,string [],intptr,intptr)
UIApplication.Main(System.String []参数,System.IntPtr主体,System.IntPtr委托)
UIApplication.Main(System.String []参数,System.StringPrincipalClassName,System.String委托ClassName)
Application.Main(System.String [] args)

BugExample.zip

@rmarinho我通过稍微改变示例来设法复制了它。

我为设置Items属性添加了100ms的延迟。

iPhone 6
iOS 12.4.5
Xamarin.Forms 4.8

从4.8.0.1364开始,此repro不再崩溃。

@mduchev @ rd09我能够得到一个简单的再现:

Bugs.zip

此repro不再在5.0.0-pre3中引发ObjectDisposedException。

我遇到相同的问题,是否有解决方案或解决方法?...这是堆栈跟踪...
我正在使用xamarin形式的最新稳定版本

@ahmedroshdy您正在使用Xamarin.Forms 4.8.0.1560看到它吗?

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

Hudhud picture Hudhud  ·  3评论

simontocknell picture simontocknell  ·  3评论

joseluisct picture joseluisct  ·  3评论

rmarinho picture rmarinho  ·  3评论

jamiewest picture jamiewest  ·  3评论