0

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

Kyle Howells
  • 3,008
  • 1
  • 25
  • 35
  • Is `Loginbutton_TouchUpInside` your button name? If so you need to handle the event for example: `Loginbutton_TouchUpInside.TouchUpInside += ...` TBH, your element names need better defined, don't name them the same as routine... – Trevor Dec 27 '19 at 14:31
  • What is this `Loginbutton_TouchUpInside` ? – Lucas Gras Dec 27 '19 at 14:32
  • @Çöđěxěŕ My button name is Loginbutton – Didrik Havasgaard Dec 27 '19 at 14:34
  • Maybe this is what you are looking for: https://stackoverflow.com/questions/19772519/cannot-assign-because-it-is-a-method-group-c – Lucas Gras Dec 27 '19 at 14:35
  • 1
    `Loginbutton.TouchUpInside += Loginbutton_TouchUpInside` should work then. As I mentioned in my first comment, you need to handle `TouchUpInside` event of the button itself; at that time I didn't have your button name... – Trevor Dec 27 '19 at 14:35
  • @DidrikHavasgaard If answer be helpful , rememeber to mark it later when have time ! Happy New Year :) – Junior Jiang Dec 30 '19 at 03:12

1 Answers1

0

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.

Trevor
  • 7,777
  • 6
  • 31
  • 50