C# 向Web视图添加html显示为空白iOS xamarin表单
我在一个Xamarin.forms项目中有一个web视图,它由一些从数据库加载的HTML填充 下面是创建web视图的XAML代码。值得注意的是,它位于GridView中C# 向Web视图添加html显示为空白iOS xamarin表单,c#,xaml,xamarin,xamarin.forms,xamarin.ios,C#,Xaml,Xamarin,Xamarin.forms,Xamarin.ios,我在一个Xamarin.forms项目中有一个web视图,它由一些从数据库加载的HTML填充 下面是创建web视图的XAML代码。值得注意的是,它位于GridView中 <WebView Grid.Row="2" x:Name="policyView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" /> 这段代码在Android上运行良好,显示HTML内容没有任何问题。然而,当在iOS上运行时,我
<WebView Grid.Row="2" x:Name="policyView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
这段代码在Android上运行良好,显示HTML内容没有任何问题。然而,当在iOS上运行时,我只是得到一个空白屏幕,我不确定为什么会发生这种情况。我尝试过将水平选项设置为fillAndExpand
,垂直选项也是如此。我的问题是如何让HTML代码出现在iOS上
谢谢。发生这种情况是因为您没有提供AppTransportSecurity(ATS)。 转到您的info.plist并添加权限
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
NSAppTransportSecurity
NSAllowsArbitraryLoads
供参考:
下面的代码是我在iOS中测试的。您可以根据您的要求进行调整
<ContentPage.Content>
<StackLayout BackgroundColor="Teal" TranslationY="64">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" BackgroundColor="Silver" Text="tets test" HeightRequest="30"
HorizontalOptions="FillAndExpand"/>
<WebView Grid.Row="1" Grid.Column="1" BackgroundColor="Red" x:Name="webView"
VerticalOptions="FillAndExpand" HeightRequest="300"
HorizontalOptions="FillAndExpand" />
</Grid>
</StackLayout>
</ContentPage.Content>
您好,谢谢您的回复。我试过了,但没有成功。如果是这样的话,我会出错吗?这对你不起作用?它不会给出错误。请尝试使用常量html字符串来测试它是否是方法
ConvertPolicy
的问题。您的网络视图可以在屏幕上显示而不显示内容,或者无法显示?好的,谢谢,下次我在电脑旁时会尝试。谢谢。@landu MSFT我尝试使用html字符串,但运气不好:-(
<ContentPage.Content>
<StackLayout BackgroundColor="Teal" TranslationY="64">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" BackgroundColor="Silver" Text="tets test" HeightRequest="30"
HorizontalOptions="FillAndExpand"/>
<WebView Grid.Row="1" Grid.Column="1" BackgroundColor="Red" x:Name="webView"
VerticalOptions="FillAndExpand" HeightRequest="300"
HorizontalOptions="FillAndExpand" />
</Grid>
</StackLayout>
</ContentPage.Content>