简体   繁体   English

使用 UnevenRows 更新 TableView 中的 ViewCell 无法正常工作 Xamarin.Forms

[英]Update a ViewCell in a TableView with UnevenRows doesn´t work correctly Xamarin.Forms

Fill the TableView with so many ViewCells, so you must scroll the page to see the last ViewCell.用这么多 ViewCell 填充 TableView,所以你必须滚动页面才能看到最后一个 ViewCell。 If you then update the last ViewCell (change the text of the label) over the Tapped-Event, the label.Text would not be updated..如果然后在 Tapped-Event 上更新最后一个 ViewCell(更改标签的文本),则 label.Text 不会更新..

PS: The ForceUpdateSize is no way the fix the solution, because on iOS the app freeze at the sixth time. PS:ForceUpdateSize 无法解决解决方案,因为在 iOS 上应用程序在第六次冻结。

<TableView Intent="Settings" HasUnevenRows="True">
    <TableRoot>
        <TableSection>
            <ViewCell x:Name="DefaultViewCell" Tapped="ItemTapped">
                 <StackLayout>
                    <Label x:Name="DefaultLabel" />
                 </StackLayout>
            </ViewCell>
                      <!--.....-->
        </TableSection>
     </TableRoot>
</TableView>

I have tested your sample code , it actually happened the phenomenon your describe.我已经测试了您的示例代码,它确实发生了您描述的现象。 Although it not happens in Android ,however it occurs in IOS .虽然它不会发生在Android中,但它会发生在IOS中。 Maybe there are something difference about Label between IOS anf Android.也许IOS和Android之间的Label有些不同。

Finally , I found a solution in IOS.最后,我在IOS中找到了解决方案。 You can set a default Text Value to Label ,then Tapped method can work .您可以将默认Text值设置为Label ,然后Tapped方法可以工作。

As Follow:如下:

<TableView Intent="Settings" HasUnevenRows="True" BackgroundColor="Accent" >
    <TableRoot>
        <TableSection>
            <ViewCell x:Name="DefaultViewCell" Tapped="DefaultViewCell_Tapped">
                <StackLayout>
                    <Label x:Name="DefaultLabel" Text="Default Text "/>
                </StackLayout>
            </ViewCell>
            ...
        </TableSection>
    </TableRoot>
</TableView>

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM