Когда я выбираю элемент из списка для открытия дочерней страницы, в IPhone ничего не происходит. все работает правильно на устройстве Android

Когда я выбираю любой элемент из списка, должна быть открыта дочерняя страница. Событие listview onselecteditem запускается, но дочерняя страница не открывается.

Я использую форму Xamarin. Версия: 3.3.0.967583 Visual Studio 2017

Вот код моей страницы XAML, где привязан мой ListView

                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <Grid Padding="8, 10 ,8, 5" BackgroundColor="#FFFFFF" HeightRequest="45" Margin="80, 0, 80, 0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="40" />
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="50" />
                                    </Grid.ColumnDefinitions>
                                    <RelativeLayout Grid.Row="0" Grid.Column="0" HeightRequest="40" WidthRequest="40">
                                        <AbsoluteLayout HeightRequest="40" WidthRequest="40">
                                            <Frame CornerRadius="{OnPlatform Android='40', iOS='20'}" BackgroundColor="#A9A9A9" HasShadow="False" OutlineColor="Transparent" BorderColor="Transparent" HeightRequest="40" WidthRequest="40" Padding="0" Margin="0" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All">
                                                <Frame CornerRadius="{OnPlatform Android='40', iOS='20'}" BackgroundColor="#A9A9A9" HasShadow="False" OutlineColor="Transparent" BorderColor="Transparent" HeightRequest="40" WidthRequest="40" Padding="0" Margin="0">
                                                    <Image Source="Profile.png" Aspect="Fill" VerticalOptions="Center" HorizontalOptions="Center" BackgroundColor="Transparent" HeightRequest="40" WidthRequest="40" Margin="-1, -1, -1, -1"></Image>
                                                </Frame>
                                            </Frame>
                                        </AbsoluteLayout>
                                        <AbsoluteLayout HeightRequest="39" WidthRequest="39">
                                            <Label Text="&#xf111;" FontSize="10" TextColor="{Binding IsOnline}" 
                                            AbsoluteLayout.LayoutFlags="All"
                                            AbsoluteLayout.LayoutBounds="1, 1, 10, 10"
                                            VerticalOptions="End" HorizontalOptions="End" >
                                                <Label.FontFamily>
                                                    <OnPlatform x:TypeArguments="x:String"
                                                    Android="Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free Solid" 
                                                    iOS="FontAwesome5FreeSolid" />
                                                </Label.FontFamily>
                                            </Label>
                                        </AbsoluteLayout>
                                    </RelativeLayout>
                                    <StackLayout Grid.Row="0" Grid.Column="1" VerticalOptions="CenterAndExpand" HeightRequest="30" Padding="2, 0, 0, 5">
                                        <Label x:Name="UserName" Text="{Binding UserName}" FontSize="14" x:Uid="{Binding RoomName}" HorizontalOptions="Start" FontAttributes="Bold" TextColor="#000000" LineHeight="0" MaxLines="1" Margin="{OnPlatform Android='0, -3, 0, 0', iOS='0, -3, 0, 0'}" LineBreakMode="TailTruncation" HeightRequest="18" />
                                        <Label Text="{Binding RequestStatus}" FontSize="12" HorizontalOptions="Start"  VerticalOptions="Start" TextColor="{StaticResource lightGray}" LineHeight="0" MaxLines="1" Margin="{OnPlatform Android='0, -5, 0, 0', iOS='0, -5, 0, 0'}" LineBreakMode="TailTruncation" HeightRequest="18" />
                                    </StackLayout>
                                    <StackLayout Grid.Row="0" Grid.Column="2" VerticalOptions="Start" HorizontalOptions="End">
                                        <Label FontSize="10" HorizontalOptions="End" TextColor="{Binding IsOnline}" Text="{Binding MessageTime}" LineHeight="1" Margin="{OnPlatform Android='0, 2, 0, 0', iOS='0, 0, 0, 0'}" />
                                        <Grid Padding="0" Margin="0">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="30" />
                                            </Grid.RowDefinitions>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="50" />
                                            </Grid.ColumnDefinitions>
                                            <Label Grid.Row="0" Grid.Column="0" Text="&#xf27a;" IsVisible="{Binding IsAcceptDisplay}" FontSize="14"
                                                    TextColor="#2FB26C" HeightRequest="30" VerticalOptions="Center" WidthRequest="30" HorizontalOptions="End" HorizontalTextAlignment="End">
                                                <Label.FontFamily>
                                                    <OnPlatform x:TypeArguments="x:String"
                                                    Android="Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free Solid" 
                                                    iOS="FontAwesome5FreeSolid" />
                                                </Label.FontFamily>
                                            </Label>
                                            <StackLayout Grid.Row="0" Grid.Column="0" IsVisible="{Binding IsPendingMessageCount}" HorizontalOptions="End" Margin="14, 0, 0, 0">
                                                <Frame VerticalOptions="Center" HorizontalOptions="End" WidthRequest="16" MinimumWidthRequest="16" HeightRequest="{OnPlatform Android='16', iOS='15'}" 
                                                       OutlineColor="#2FB26C" BackgroundColor="#2FB26C" CornerRadius="{OnPlatform Android='20', iOS='8'}" 
                                                       Margin="0, 0, 0, 0" Padding="{OnPlatform Android='0', iOS='0, 1, 0, 0'}" HasShadow="False">
                                                    <Label Text="{Binding PendingMessageCount}" FontSize="{OnPlatform Android='8', iOS='7'}" FontAttributes="Bold" VerticalOptions="CenterAndExpand" VerticalTextAlignment="Center"
                                                    TextColor="#FFFFFF" HorizontalOptions="Center" HorizontalTextAlignment="Center" HeightRequest="16" LineHeight="0.8"></Label>
                                                </Frame>
                                            </StackLayout>
                                        </Grid>
                                    </StackLayout>
                                </Grid>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                    <ListView.Footer>
                        <StackLayout Orientation="Horizontal"></StackLayout>
                    </ListView.Footer>
                </ListView>
            </StackLayout>
        </AbsoluteLayout>
    </StackLayout>

Ниже находится страница XAML.CS, на которой я управлял событием OnItemSelected

 async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
    {
        try
        {
             var item = args.SelectedItem as User;

            if (item == null)
                return;

            App.chatBoxPage = null;
            App.chatBoxPage = new ChatBoxPage(new ChatViewModel(item));
            await Navigation.PushAsync(App.chatBoxPage);
            ChatList.SelectedItem = null;

        }
        catch (Exception e)
        {
            await DisplayAlert("Live Chat", "On Clicked  : " + e.ToString(), "OK");
        }
    }

Иногда возникает исключение ниже

 System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.VisualElement.get_BackgroundColor () <0x10178c450 + 0x00028> in <81ae0eb290e24f558e192928e3e37a57#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) <0x1018a4620 + 0x000a3> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) <0x1018a4020 + 0x0003f> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) <0x10189cd70 + 0x0007b> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) <0x1018a2a70 + 0x000af> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () <0x1018a26e0 + 0x000ab> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) <0x1018a4620 + 0x003c7> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) <0x1018a4020 + 0x0003f> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) <0x10189cd70 + 0x0007b> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+UnevenListViewDataSource.CalculateHeightForCell (UIKit.UITableView tableView, Xamarin.Forms.Cell cell) <0x1018f0fe0 + 0x000b7> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+UnevenListViewDataSource.GetEstimatedRowHeight (UIKit.UITableView table) <0x1018f0af0 + 0x0021b> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateEstimatedRowHeight () <0x1018c0970 + 0x0010f> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) <0x1018bf1a0 + 0x00b3b> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) <0x1018a4620 + 0x004cb> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) <0x1018a4020 + 0x0003f> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) <0x10189cd70 + 0x0007b> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) <0x1018a2a70 + 0x000af> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () <0x1018a26e0 + 0x000ab> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) <0x1018a4620 + 0x003c7> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) <0x1018a4020 + 0x0003f> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) <0x10189cd70 + 0x0007b> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) <0x1018a2a70 + 0x000af> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () <0x1018a26e0 + 0x000ab> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) <0x1018a4620 + 0x003c7> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) <0x1018a4020 + 0x0003f> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) <0x10189cd70 + 0x0007b> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) <0x1018a2a70 + 0x000af> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () <0x1018a26e0 + 0x000ab> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) <0x1018a4620 + 0x003c7> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) <0x1018a4020 + 0x0003f> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) <0x10189cd70 + 0x0007b> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) <0x1018a2a70 + 0x000af> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () <0x1018a26e0 + 0x000ab> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
 at Xamarin.Forms.Platform.iOS.PageRenderer.ViewDidLoad () <0x1018c9b80 + 0x0034f> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at PSS_LiveChat.iOS.IosKeyboardFixPageRenderer.ViewDidLoad () <0x10089e900 + 0x0001b> in <39287061e96f454f92c45a96e90470c1#40b0903c179c66f2f42ecc37469bd36a>:0 
  at (wrapper managed-to-native) ObjCRuntime.Messaging.objc_msgSendSuper(intptr,intptr)
  at UIKit.UIViewController.get_View () <0x10149e8c0 + 0x0006f> in <bbd12705940f4bb29392519af87b535b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.PageRenderer.get_NativeView () <0x1018c9630 + 0x00023> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.PageRenderer.SetElement (Xamarin.Forms.VisualElement element) <0x1018c9670 + 0x000ef> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) <0x10189cd70 + 0x0007b> in<85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.CreateViewControllerForPage (Xamarin.Forms.Page page) <0x1018c5e10 + 0x00027> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer+<OnPushAsync>d__51.MoveNext () <0x1018f95a0 + 0x0007b> in <85a5f025a15045539371e93897914a5b#40b0903c179c66f2f42ecc37469bd36a>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Xamarin.Forms.NavigationPage+<PushAsyncInner>d__84.MoveNext () <0x10174c7f0 + 0x0023f> in <81ae0eb290e24f558e192928e3e37a57#40b0903c179c66f2f42ecc37469bd36a>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Xamarin.Forms.NavigationPage+<PushAsync>d__55.MoveNext () <0x10174b730 + 0x00523> in <81ae0eb290e24f558e192928e3e37a57#40b0903c179c66f2f42ecc37469bd36a>:0 
--- End of stack trace from previous location where exception was thrown ---
  at PSS_LiveChat.Views.LiveChatPage+<OnItemSelected>d__5.MoveNext () <0x100cfb210 + 0x0040f> in <3b5956d19f5f4bdc84324069625851ef#40b0903c179c66f2f42ecc37469bd36a>:

person MishaTech    schedule 18.04.2019    source источник
comment
Я обновил версию Xamarin Forms: 3.3.0.967583 до последней версии 3.6.0.344457, но проблема все еще остается. Раньше часто возникала проблема с iPhone SE, но теперь проблема возникает на всех устройствах iOS.   -  person MishaTech    schedule 13.05.2019


Ответы (1)


Я считаю, что причина этого в том, что вы используете событие ItemSelected, когда вы должны использовать событие ItemTapped, поскольку событие выбора элемента будет запущено только тогда, когда вы выберете новый Item, если вы дважды щелкните один и тот же элемент, оно не сработает.

Ваш ListView должен выглядеть примерно так:

<ListView ItemTapped = "ListView_ItemTapped".../>

И ваше событие ItemTapped в файле cs будет выглядеть примерно так:

 private void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
    {
        // Your code
    }
person FreakyAli    schedule 18.04.2019
comment
Когда добавлен новый элемент списка, и если щелкнуть по нему в течение двух секунд, это вызовет ошибку из кода await Navigation.PushAsync (App.chatBoxPage); - person MishaTech; 18.04.2019
comment
Вы уверены, что добавили NavigationPage, чтобы использовать Navigation.PushAsync? - person FreakyAli; 18.04.2019
comment
да, потому что ошибка возникает только при нажатии на вновь добавленный элемент списка, если я жду 3 секунды, все работает нормально. - person MishaTech; 18.04.2019