简体   繁体   中英

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. 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. 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;

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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