IOS TableView have more than 2 ViewCell , app come back from background, tableview will not display ?

Fei Xu 490 Reputation points
2023-06-06T15:20:29.18+00:00

IOS TableView have more than 2 ViewCell , app come back from background, tableview will not display ?

Only IOS and more than 2 viewcell have this problem.

ezgif.com-video-to-gif

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TableViewDemos.viewcelltest"
             Title="viewcelltest">
    <TableView Intent="Menu">
        <TableRoot>
            <TableSection>
                <ViewCell x:Name="viewCellTools" >
                    <Grid>
                        <Label Text="常用工具" Margin="20,0,0,0" VerticalOptions="Center" HorizontalOptions="Start"/>
                        <Label Text=">" Margin="0,0,20,0" VerticalOptions="Center" HorizontalOptions="End"/>
                    </Grid>
                </ViewCell>
                <ViewCell x:Name="viewCellJoinClass">
                    <Grid>
                        <Label Text="加入班级" Margin="20,0,0,0" VerticalOptions="Center" HorizontalOptions="Start"/>
                        <Label Text=">" Margin="0,0,20,0" VerticalOptions="Center" HorizontalOptions="End"/>
                    </Grid>
                </ViewCell>
                <ViewCell >
                    <Grid>
                        <Label Text="加入班级" Margin="20,0,0,0" VerticalOptions="Center" HorizontalOptions="Start"/>
                        <Label Text=">" Margin="0,0,20,0" VerticalOptions="Center" HorizontalOptions="End"/>
                    </Grid>
                </ViewCell>

            </TableSection>
        </TableRoot>
    </TableView>
</ContentPage>

iOS16.4 VS 17.7 Pre .Net7

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,844 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 25,996 Reputation points Microsoft Vendor
    2023-06-07T08:35:22.3933333+00:00

    Hello,

    I can reproduce your issue. You could try to wrap the Grid with a Border or Frame, the viewcell won't disappear. You could also try replacing the TableView with ListView.

    Update

    add frame android will disappear

    For this, you could set different UI based on the platform. See Customize UI appearance based on the platform and device idiom - .NET MAUI | Microsoft Learn

    <ContentPage ...>
        <TableView Intent="Menu">
            <TableRoot>
                <TableSection>
                   <OnPlatform x:TypeArguments="ViewCell">
                        <On Platform="iOS">
                            <ViewCell  >
                       
                        <Frame>
                        <Grid>
                            ...
                        </Grid>
                            </Frame>
                    </ViewCell>
    
                        </On>
                        <On Platform="Android">
                            <ViewCell>
                        <Grid>
                           ...
                        </Grid>
                              </ViewCell>
                        </On>
                    </OnPlatform>
    
                    ... other viewcells
    
                </TableSection>
            </TableRoot>
        </TableView>
    </ContentPage>
    

    There is a same issue reported at Github- ListView ViewCell content disappears when the application enters the foreground · Issue #11640 · dotnet/maui · GitHub, please follow the progress.

    Update

    As you Fei Xu said, adding frame for iOS have another problem, second label will cover with first label even HorizontalOptions="End"

    So, you use TextCell for this function temporary.

    Thanks for your sharing.

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.