简体   繁体   English

无法分配给“Loginbutton_TouchUpInside”,因为它是“方法组”

[英]Cannot assign to 'Loginbutton_TouchUpInside' because it is a 'method group

I've been trying to figure out the error of my ways but neither I, Google nor MSDN will can figure it out.我一直试图找出我的方法的错误,但我、谷歌和 MSDN 都无法弄清楚。 It would probably be easy enough if I knew exactly what I was looking for but been trying everything I've come over.如果我确切地知道我在寻找什么,但一直在尝试我遇到的一切,这可能会很容易。 At this point I am reaching out to all the guru's out there for a straight answer.在这一点上,我正在向所有的大师寻求直接的答案。 I'm running Xamarin on Visual Studio 2019, building an iOS app.我在 Visual Studio 2019 上运行 Xamarin,构建一个 iOS 应用程序。 Enough backstory, let's introduce the problem:说完了背景,我们来介绍一下问题:

public partial class LoginViewController : UIViewController
{
    public LoginViewController(IntPtr handle) : base(handle)
    {
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        Loginbutton_TouchUpInside += Loginbutton_TouchUpInside;
    }

    private void Loginbutton_TouchUpInside(object sender, EventArgs e)
    {
        DatabaseReference reference = Database.DefaultInstance.GetRootReference().GetChild("Login");
        reference.SetValue<NSString>((NSString)"Connection is Successful");
    }

}

My issue is with this line:我的问题是这一行:

Loginbutton_TouchUpInside += Loginbutton_TouchUpInside;

Thanks in advance Didrik提前致谢

My issue is with this line: Loginbutton_TouchUpInside += Loginbutton_TouchUpInside;我的问题是这一行: Loginbutton_TouchUpInside += Loginbutton_TouchUpInside;

The error as already mentioned is correct:已经提到的错误是正确的:

 "Cannot assign to 'Loginbutton_TouchUpInside' because it is a 'method group"

You are trying to assign a method to a method, not possible.您正在尝试将方法分配给方法,这是不可能的。 What you are wanting to do is handle the TouchUpInside event.您想要做的是处理TouchUpInside事件。 In order to do so, you need to assign that button's event to the new method.为此,您需要将该按钮的事件分配给新方法。

 Loginbutton.TouchUpInside += Loginbutton_TouchUpInside

Now when the button is tapped, it will be handled by the Loginbutton_TouchUpInside method/routine.现在,当点击按钮时,它将由Loginbutton_TouchUpInside方法/例程处理。

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

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