【问题标题】:HybridWebView .LoadContent doesn't LoadContent on iosHybridWebView .LoadContent 不会在 ios 上加载内容
【发布时间】:2016-05-04 04:03:11
【问题描述】:

轻松一天,给你的朋友留下深刻印象!

来自 xlabs 的 Hybridwebview - https://github.com/XLabs/Xamarin-Forms-Labs/wiki/HybridWebView

正在尝试加载内容,如下所示。

在 android 上运行良好,在 ios 上使用 str 或 str2 都没有显示。

有什么想法吗?

CSHARP

    void OnButtonStaticLoadClicked(object sender, EventArgs args)
    {
        // doesnt load on ios
        string str = @"<html><body><h2>hello there</h2><div>four score and seven years ago </div></body></html>";
        string str2 = @"<!DOCTYPE html>" +
            @"<html>" +
            @"<body bgcolor='yellow'><h2>hello there</h2><div style='font-color:black'>four score and seven years ago</div>" +
            @"</body></html>";

        HybridWebView_Main.LoadContent(str2);
    }

XAML

<StackLayout>
  <Button x:Name="Button_LoadStatic" Text="Load Static HTML" Clicked="OnButtonStaticLoadClicked" />
  <controls:HybridWebView x:Name="HybridWebView_Main"
                      HorizontalOptions="FillAndExpand"
                      VerticalOptions="FillAndExpand"
                      BackgroundColor="Yellow"
                      HeightRequest="300" />
</StackLayout>

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    由于某种原因,渲染器未注册。添加

    [assembly: ExportRenderer(typeof(HybridWebView), typeof(HybridWebViewRenderer))]
    

    在您的 iOS 代码中,它会起作用。

    【讨论】:

    • 注意:我在我的 HybridWebViewPlay.iOS 项目中的 AppDelegate.cs 的命名空间之外添加了它... [程序集:ExportRenderer(typeof(HybridWebView), typeof(HybridWebViewRenderer))] 命名空间 HybridWebViewXLabs。 iOS { // 应用程序的 UIApplicationDelegate。这个类负责启动 ...
    • 是的,程序集属性必须放在文件中的任何其他声明之前:)
    • 我在使用 .Net Native 工具链编译 UWP 应用程序时遇到了这个问题。没有 .Net Native 工具链,一切都很好;但是一旦我启用它,该应用程序只显示一个空白页面。添加渲染器程序集解决了这个问题!谢谢!
    猜你喜欢
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多