繁体   English   中英

Xamarin IOS-类没有默认的无参数构造函数

[英]Xamarin IOS - class does not have a default parameterless constructor

我在Xamarin IOS应用中不断收到以下错误。 我的应用程序运行良好,但Apple一直拒绝它,因此我认为这是由该错误引起的。 错误是:“ Y4P.Views.PlayVideo类没有默认的无参数构造函数。除非添加无参数构造函数,否则无法预览此xaml文件。如果该类具有一个,则该构造函数应调用标准的“初始化组件”方法。

XAML代码:

    <?xml version="1.0" encoding="UTF-8"?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:forms="clr-namespace:InTheHand.Forms;assembly=InTheHand.Forms"
              x:Class="Y4P.Views.PlayVideo"
             Title="{Binding Title}">
    <StackLayout Margin="20,20,20,20">
     <forms:MediaElement HorizontalOptions="Fill" BackgroundColor="White" VerticalOptions="Center" HeightRequest="650" x:Name="Media" IsLooping="False"  AreTransportControlsEnabled="true" Source="{Binding URL}"/>
    </StackLayout>

</ContentPage>



    using System;
    using System.Collections.Generic;
    using AVFoundation;
    using AVKit;
    using Foundation;
    using Xamarin.Forms;
    using Y4P.Models;
    using Y4P.ViewModels;
    using System.Threading.Tasks;
    using Xamarin.Forms.Xaml;

    namespace Y4P.Views
    {
        public partial class PlayVideo : ContentPage
        {
            ItemDetailViewModel viewModel;

            public PlayVideo(ItemDetailViewModel viewModel)
            {

                InitializeComponent();
                BindingContext = this.viewModel = viewModel;

            }
        }
    }

Y4P.Views.PlayVideo类没有默认的无参数构造函数。 除非添加了无参数构造函数,否则无法预览此xaml文件。 如果类具有一个,则此构造方法应调用标准的“初始化组件”方法。

根据您共享的代码,这是真的。 因此,如果要摆脱此错误,请添加无参数构造函数,以便可以预览XAML:

public PlayVideo()
{
    InitializeComponent();
}

我的应用程序运行良好,但苹果一直拒绝

关于上面的陈述,它不太可能与无参数构造函数有关。 通常,Apple提供的反馈包含可能被违反的单个或多个要点。 我建议重新检查他们的回应并采取相应的行动。

暂无
暂无

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

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