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
{{
保護されたオーバーライドvoidDispose(bool dispose)
{{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(disposed);
}
}
}

全てのコメント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

1か月間リリースされた、他の方法で機能するアプリのリビジョンから、これと同じエラーが発生しました。

iOS12.4.1で発生しました。 AppCenterからの報告のため、詳細が限られており、再現できませんでした。 ほとんどの人は決してそれに遭遇しないようです。

@BioTurboNickどのバージョンのXamarinフォームを使用していますか? あなたの問題は他の何かのように見えるからです。
上記のエラーは再現が非常に簡単で、ページを切り替えるたびに発生します。

うーん、多分そうです。 私は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

このバグは、単純な(私が思うに)コレクションビューで発生します。XamarinForms4.4.0.991265を使用しており、リストビューで正常に機能します。

  <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] in / Users / builder / jenkins / workspace / xamarin-macios / xamarin-macios / external / 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 index、T item)[0x0001a] in / Users / builder / jenkins / workspace / xamarin-macios / xamarin-macios / external / mono / external / corefx / src / System.ObjectModel / src / System / Collections / ObjectModel / ObservableCollection.cs:196
System.Collections.ObjectModel.Collection`1 [T] .Add(T item)[0x00020]で/ Users / builder / jenkins / workspace / xamarin-macios / xamarin-macios / external / mono / external / corefx / src / 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.Forms4.4.0.991640の使用

@hartezありがとう。 これは、iOSでシェルを使用できなくする重大なバグです。

同じ問題があり、バグのあるアプリを公開できません。修正してください。

ここで同じ問題。

ここで同じ問題

シェルなし、ヘッダーなし、フッターなしの4.4.0.991640でも同じ問題が発生します。

また、内部に同じものがあると私が想像するカルーセルビューを使用して発生します

さあ、Xamarinチーム... 5か月間、本番環境でクラッシュするバグが発生することは本当に許容できますか?

@PureWeen @hartez @samhouts

4.5より前にこのバグがあったことはありません。
4.5に更新した後、このバグはCollectionView(シェルなし)に表示されます。

ここでのホットリロードに関する同じ問題:
私の場合、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>

`

テンプレートで何かを変更するたびに、[保存]をクリックしてホットリロードを開始すると、エラーが発生します(シミュレーター内のiOS 13、実際のデバイスのiOS 12)

すべてのリストビュー/テンプレートで発生するわけではなく、違いが何であるか、またはそれを回避する方法がわかりません...これまでは、迷惑ですが重要ではないホットリロードでのみ発生します-しかし、それを読んだときにあなたは通常の実行時にこれを持っています私は少し恐れています...

スタックトレースは次のとおりです。

`破棄されたオブジェクトにアクセスできません。
オブジェクト名: 'DefaultRenderer'。

Foundation.NSObject.get_SuperHandle()[0x00012]の/Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.3.0/src/Xamarin.iOS/Foundation/NSObject2.cs:449
/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()[0x000a5]のD:\ a \ 1 \ s \ Xamarin.Forms.Platform.iOS \ Cells \ ViewCellRenderer.cs:103
at(ラッパー管理からネイティブ)ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_Int64(intptr、intptr、intptr、long)
UIKit.UITableView.ReloadRows(Foundation.NSIndexPath [] atIndexPaths、UIKit.UITableViewRowAnimation withRowAnimation)[0x0002a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.3.0/src/Xamarin.iOS/UITableView.g。 cs:824
Xamarin.Forms.Platform.iOS.CellRenderer + <> c__DisplayClass8_0で。b__0(System.Object送信者、System.EventArgs e)[0x00032] in D:\ a \ 1 \ s \ Xamarin.Forms.Platform.iOS \ Cells \ CellRenderer.cs:106
Xamarin.Forms.Cell.OnForceUpdateSizeRequested()[0x00076]のD:\ a \ 1 \ s \ Xamarin.Forms.Core \ Cells \ Cell.cs:234 `

私も私のアプリでこの問題を抱えています。 高さ100の非表示のボックスビューを持つ対応するページのコレクションビューのフッターを削除すると(ビューの下部にスペースを追加するため)、問題が解決します。
正常に機能する別のことがあります。シェルページに複数のflyoutitem定義があります。 flyoutitem定義が1つしかない場合、この問題は発生しません。 したがって、すべてのシェルコンテンツが1つのフライアウトアイテムに含まれるようにシェルフライアウトを設計できれば、問題は解決します。

サンプルプロジェクトの@Genfoodの場合、問題はItemsPageのcollectionviewのヘッダーにあります。 削除すると問題は解決しますが、ヘッダーの設定の有無にかかわらずクラッシュすることはありません。 上記のように、あなたができるもう一つのことは、すべてのフライアウトアイテムを1つに結合することです。 その後、それも機能します。

この厄介なバグを修正する必要があります

@samhouts修正はいつリリースされますか?

@ g4mb10rこれはhttps://github.com/xamarin/Xamarin.Forms/releases/tag/beta-4.6.0-pre4.2でリリースされました

@samhoutsそのバージョンを試したところ、問題は解決しません。

System.ObjectDisposedException
メッセージ=破棄されたオブジェクトにアクセスできません。
オブジェクト名: 'WkWebViewRenderer'。

私も同じ問題に直面しています

@samhoutsこれは修正されていません。

新しくリリースされた4.6安定版でテストしました。 そして、それは修正されたようです。 🎉
少なくとも、この問題に添付したバグの例は現在機能しています。

@samhouts CollectionViewがある場合は修正されますが、WebViewがある場合は修正されません。 それはまだ壊れています。 おそらく他にもいくつかあります。

@samhoutsそのバージョンを試したところ、問題は解決しません。

System.ObjectDisposedException
メッセージ=破棄されたオブジェクトにアクセスできません。
オブジェクト名: 'WkWebViewRenderer'。

@ g4mb10rこれは、最初に投稿された問題とは異なるコントロールからの異なるエラーです。 ObjectDisposedExceptionsには多くの原因が考えられます。

あなたの情報(それはWkWebviewRendererである)で新しい問題を開き、あなたが持っている他の情報(スタックトレース、可能であれば再現プロジェクト)を含めてください。

@ samhoutsv1.6のCollectionViewsでこの問題が発生しています。 トレースは次のとおりです。

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

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

Xamarin.Forms.Platform.iOS.ItemsViewController`1 [TItemsView] .LayoutEmptyView()[0x0000f]のD:\ a \ 1 \ s \ Xamarin.Forms.Platform.iOS \ CollectionViewItemsViewController.cs:318

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

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

at(ラッパー管理からネイティブ)UIKit.UIApplication.UIApplicationMain(int、string []、intptr、intptr)

UIKit.UIApplication.Main(System.String [] args、System.IntPtrプリンシパル、System.IntPtrデリゲート)[0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS /UIKit/UIApplication.cs:86

UIKit.UIApplication.Main(System.String [] args、System.StringprincipalClassName、System.StringdelegateClassName)[0x0000e]の/Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS /UIKit/UIApplication.cs:65

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

問題の原因を正確に特定することはできませんが、シェルを使用してflyoutitem内のいくつかのタブにCollectionViewsがあります。 各CollectionViewはグループヘッダーを使用します。

CollectionViewを使用してタブをロードすることは問題ありません。次に、2番目のタブも問題ありません。 以前に表示したものに戻ろうとすると、クラッシュが発生します。

私はこれをサンプルプロジェクトで複製しようと取り組んでいますが、今のところできていません。 また、Androidでは問題は発生していません。

編集

原因を見つけたようで、新しいIssue#10953を開きました。 元のポスターの問題に関連しているかどうかはわかりません。

これはiOSのv4.7.0.1080でもまだ壊れています。 Androidは大丈夫です。

3x異なるページの3xCollectionViews、ヘッダーまたはフッターなし。 シェルを使用せず、通常の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このバグはiOSv12.4では再現できません。

私はまだこれをIOS12.4.5を実行しているXamarin.Formsの最新バージョンを実行しています。

iOS 12.4.1(13.xではない)とXamarin.Forms4.7を実行してこれを再現できます。 もう一度バグを開いてください。

@ robintschroeder@ daves1992 BugExampleを使用して再現できますか?

@rmarinhoはい、12.4.5を実行しているiPhone 6でテストしたばかりで、BugExampleを初めて使用して再現できました。

System.ObjectDisposedException: '破棄されたオブジェクトにアクセスできません。
オブジェクト名: 'GroupableItemsViewController`1'。 '

iOS 12.2シミュレータで4.8でテストしましたが、動作しているようです。

サンプルのXamarin.Formsを更新するのを忘れてしまいました。 4.8にアップデートしましたが、サンプルやアプリで再現できませんでした...先日毎回再現されなかったため、4.7.Xで100%だったので、注意が必要です。

バグはxamarin4.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 [] args、System.IntPtrプリンシパル、System.IntPtrデリゲート)
UIApplication.Main(System.String [] args、System.StringprincipalClassName、System.StringdelegateClassName)
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を使用しても、iOS12で同じ問題が発生します。 これらのデバイスでCollectionviewがクラッシュしています。 この問題を再開する必要があります。

このバグの回避策を見つけました。 Collectionviewのカスタムレンダラーを作成し、Disposeメソッドをオーバーライドします。
カスタムレンダラーコードは次のとおりです。

[アセンブリ:ExportRenderer(typeof(CollectionView)、typeof(CustomCollectionViewRenderer))]
名前空間Project.iOS.Renderers
{{
パブリッククラスCustomCollectionViewRenderer:CollectionViewRenderer
{{
保護されたオーバーライドvoidDispose(bool dispose)
{{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(disposed);
}
}
}

このバグの回避策を見つけました。 Collectionviewのカスタムレンダラーを作成し、Disposeメソッドをオーバーライドします。
カスタムレンダラーコードは次のとおりです。

[アセンブリ:ExportRenderer(typeof(CollectionView)、typeof(CustomCollectionViewRenderer))]
名前空間Project.iOS.Renderers
{{
パブリッククラスCustomCollectionViewRenderer:CollectionViewRenderer
{{
保護されたオーバーライドvoidDispose(bool dispose)
{{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(disposed);
}
}
}

共有していただきありがとうございます。 これを試してみます。 また、この問題に関して大量のクラッシュが発生しています。

このバグの回避策を見つけました。 Collectionviewのカスタムレンダラーを作成し、Disposeメソッドをオーバーライドします。
カスタムレンダラーコードは次のとおりです。

[アセンブリ:ExportRenderer(typeof(CollectionView)、typeof(CustomCollectionViewRenderer))]
名前空間Project.iOS.Renderers
{{
パブリッククラスCustomCollectionViewRenderer:CollectionViewRenderer
{{
保護されたオーバーライドvoidDispose(bool dispose)
{{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(disposed);
}
}
}

一部のヒーローはケープを着用していません

@rmarinho @samhoutsこのバグを再開できますか? 上記のサンプルの調整済みバージョンを使用して再度複製することができましたが、より多くの人が問題を抱えているようです。

最新のフォームでも同じ問題が発生しています。 シェル、ヘッダー、フッターはありません。

同じ問題が発生していますが、iOS12.4.8を実行しているiPadとiOS12.4.1を実行しているiPhoneのListViewを使用していますが、iOS13のデバイスでは使用していません。iOS13.4を対象とするXamarinForms 4.7SR5を使用しています。

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の回避策はありますか?

@ rd09ListViewはGroupableItemsViewControllerを使用しません。 CollectionViewを使用していないことを確認しますか?

@ rd09ListViewはGroupableItemsViewControllerを使用しません。 CollectionViewを使用していないことを確認しますか?

頭を上げてくれてありがとう、あなたは正しいです。 どういうわけか、ソースコードを調べて確認した後、

@ 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

これはiOS12でも見られますが、これまでのところ回避策は見つかりませんでした。

私はiPadにもこのバグがあります

  • XAMARIN 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
{{
保護されたオーバーライドvoidDispose(bool dispose)
{{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(disposed);
}
}
}

@ l0gaw iOSプロジェクトにCustomRendererのみを実装する必要がありますか、それともメインプロジェクトに他のものが必要ですか?

@matheuscschenfeldiOSプロジェクトで

また、まだこの問題が発生していますが、回避策ではこれは修正されません

編集
問題を修正しました。 viewmodelコマンドの代わりにmodelコマンドへのバインドを行っていました。 ビューモデル間を行ったり来たりするときに、このバインディングは更新されませんでした。 そのため、新しいビューモデルソースのコレクションアイテムを閉じる代わりに、すでに破棄されているコレクションからアイテムを削除したいと考えていました。
モデルではなくビューモデルへのバインディングを変更するときに問題が発生しなくなりました。

SelectedItemをnullに設定する行がSelectedItemイベントをトリガーするため、投稿された回避策の使用には注意する必要があります。そのため、そのプロパティに双方向バインディングが設定されていて、nullをチェックしていない場合は、例外が発生します。 回避策には必要ないと思うので、行を完全に削除しました。

@samhoutsこれがすぐに取り上げられるかどうかに関する最新情報。 同じ問題がリストビューでも発生しています。 フォームバージョン4.7.0.1080

これはXamarin.Forms5.xで修正されるか、MAUIまで待つ可能性があると思います。 私は間違っていることを願っています

iOSシミュレーターのXamarin4.8でもこの問題を再現しています

@ samhouts @ hartez多くの人がまだこのかなり大きなバグを報告しています。 このバグの範囲は小さすぎて、実際の問題をカプセル化できませんでした。

これがまだ修正されていないことは非常に印象的です、私もこのバグを抱えています、CollectionViewはiOSで正しく動作しませんでした

@ l0gawの回避策は以前は機能していましたが、現在は機能していません。 それが最後のiOSアップデートからのものかどうかはわかりませんが、それは本当に厄介になっています-単純なアップデート/クリアからどこでもクラッシュします。

@mduchev私もこれを見ています。 これはiOS13と14の両方で発生しています。私にとって変更されたのはXamarin.iOS14に移行することだけでした。今すぐ回避策を考え出すことができるかどうかを確認しようとしています。

具体的には、これが私が今見ているスタックです:

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 ()

コレクションからアイテムを削除しますか? もしそうなら、あなたは別の報告された問題にぶつかったかもしれません(私も絶えずぶつかっています

前回投稿した号を再現することができました。 CollectionViewがある画面に移動し、アイテムを追加または削除して変更すると、画面を閉じるとこの例外がスローされます。 同じ画面に移動し、CollectionViewを変更しない場合、画面を終了しても例外はスローされません。 回避策はまだ機能していますが、CollectionViewをクリアするとクラッシュするため、一部の領域をリファクタリングする必要がありました。 したがって、回避策は間違いなく新しい問題をもたらします。 現時点で最も安全な方法は、CollectionViewsを使用しないことだと思います。

同じ問題があります。
シナリオは

  • カルーセルビューを作成する
  • カルーセルビューテンプレート内でcollectionviewを使用する
  • たとえば、カルーセルアイテムとコレクションアイテムをクリックします。 それらの状態を変更する-cliecked
  • xamlパーツを更新して、ホットリロードでビューが更新されたかどうかを確認してください
  • カルーセルビューをクリックします-コレクションビューアイテムをもう一度クリックします

その時点で、私の経験にエラーが発生します。

  • iOSシミュレーターのデバッグモードで発生します
  • しかし、リリースモードで展開されたiPhoneデバイスでは再現できませんでした。
  • エラーは、私にとってデバッグモードでのみ発生します。

誰かが最新のXamarinパッケージを使用してサンプルプロジェクトを提供できれば、修正ははるかに簡単になります。 これが絶えず起こっているとき、私は正確なケースを正確に特定することができないようです。 可能であれば、問題を説明するデモプロジェクトを提供して、迅速に修正できるようにしてください。

@mduchev @ daves1992からのこのコメントを見ましたか?

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

コメントの洪水に少し埋もれているので、ただ尋ねるだけです。 それはあなたのために問題を再現しませんか?

@lafritay残念ながら、

@lafritay残念ながら、

どのバージョンのIOS?

私はそれを12.4.1で複製することができましたが、それ以降のバージョンでは複製されなかったと思います。

誰かが最新のXamarinパッケージを使用してサンプルプロジェクトを提供できれば、修正ははるかに簡単になります。 これが絶えず起こっているとき、私は正確なケースを正確に特定することができないようです。 可能であれば、問題を説明するデモプロジェクトを提供して、迅速に修正できるようにしてください。

再作成するには、iOS12を使用している必要があります。

@ rd09真実ではありません。 iOS 13デバイスでも同じエラーが発生していましたが、iOS14デバイスでも同じエラーが発生しています。 残念ながら、サンプルプロジェクトは問題を再現していないようですので、他の形でまだ残っていると思います。

再現+ソリューション: 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メソッドにあると思います: httpsItemsSourceが保持する値は破棄されませんが、オブジェクトの存続期間を所有しているように見えます。

これは、Androidの対応物がオブジェクトを破棄するという事実によって確認されているようです(このファイルのUpdateItemsSource

そして、これが引き続き発生する大きな理由の1つは、多くの人が使用している回避策が、disposeが呼び出されたときにItemsSourceをnullにすることだと思います。

@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、layout);
}
}
}

Xamarin.Formsを使用します。
Xamarin.Forms.Platform.iOSを使用する;

名前空間Example.iOS.Renderers
{{
パブリッククラスCustomGroupableItemsViewController:GroupableItemsViewController
ここで、TItemsView:GroupableItemsView
{{
public CustomGroupableItemsViewController(TItemsView selectableItemsView、ItemsViewLayout layout):base(selectableItemsView、layout)
{{
}

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

}

システムを使用する;
Foundationを使用する。
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
{{
保護されたオーバーライドvoidDispose(bool dispose)
{{
base.ItemsView.SelectedItem = null;
base.ItemsView.ItemsSource = null;
base.Dispose(disposed);
}
}
}

@ l0gaw iOSプロジェクトにCustomRendererのみを実装する必要がありますか、それともメインプロジェクトに他のものが必要ですか?

この回避策は私の場合はうまくいきました。 @ rd09が言ったように私の場合は必要ないので、「ItemsView.SelectedItem = null」という行も削除しました。

同じ問題が私に起こりました、解決策または回避策?...これはスタックトレースです...
xamarinフォームの最新の安定バージョンを使用しています
AppShellを使用する
iOS12で発生します
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 [] args、System.IntPtrプリンシパル、System.IntPtrデリゲート)
UIApplication.Main(System.String [] args、System.StringprincipalClassName、System.StringdelegateClassName)
Application.Main(System.String [] args)

BugExample.zip

@rmarinhoサンプルを少し変更することで、なんとか複製できました。

Itemsプロパティの設定に100msの遅延を追加しました。

iphone 6
IOS 12.4.5
Xamarin.Forms 4.8

この再現は、4.8.0.1364以降でクラッシュしなくなりました。

@mduchev @ rd09簡単な再現を得ることができました:

Bugs.zip

この再現では、5.0.0-pre3でObjectDisposedExceptionがスローされなくなりました。

同じ問題が私に起こりました、解決策または回避策?...これはスタックトレースです...
xamarinフォームの最新の安定バージョンを使用しています

@ahmedroshdy Xamarin.Forms 4.8.0.1560を使用してこれを確認していますか?

このページは役に立ちましたか?
0 / 5 - 0 評価