iOS App crashes when stack removing layout children (Xamarin Forms)

hussamhussam USMember, University

I am using Xamarin Forms 1.3.1, and I want to load items from a cloud data store and display them in a ListView. While the items are being fetched, I want to display an ActivityIndicator that will disappear once the items are fetched. However, when I remove the ActivityIndicator from the StackLayout the application (iOS) crashes without raising an exception or anything. This happens right after calling layout.Children.Clear() or layout.Children.RemoveAt(0). Any help?

Here is my code below. DataStore.FetchData(callback) calls the passed in callback function once the data is ready.

    public class MyPage : ContentPage
        {
            public MyPage ()
            {
                Content = new StackLayout {
                            VerticalOptions = LayoutOptions.CenterAndExpand,
                            HorizontalOptions = LayoutOptions.Center,
                            Children = {
                                new Label { Text = "Loading data..." },
                                new ActivityIndicator { IsRunning = true }
                            }
                        };
            }

            protected override void OnAppearing ()
            {
                base.OnAppearing ();
                DataStore.FetchData ( () => {
                    Settings.ContactsFetched = true;
                    var layout = (StackLayout) Content;
                    layout.Children.Clear();
                });
            }
        }

Thanks,

Posts

  • hussamhussam USMember, University

    Ah, it turns out that the issue was in asynchronous continuations using ContinueWith inside my implementation of DataStore.FetchData() -- clearing layout children is not an issue.

    Cheers,

Sign In or Register to comment.