Reputation: 23
I am currently making a simple calculator app for the iPhone using Xamarin.iOS. I have tried doing Button click = (Button)sender;
but it seems like it does not work. It keeps saying that 'Button' could not be found even though I have set that name in the storyboard.
This is what I have so far (I am writing this in my ViewController.cs file):
using Foundation;
using System;
using UIKit;
using System.Collections.Generic;
namespace app1
{
public partial class ViewController : UIViewController
{
public ViewController(IntPtr handle) : base(handle)
{
}
public string[] number = new string[2];
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
Button1.TouchUpInside += (object sender, EventArgs e) =>
{
Button click = (Button)sender;
};
}
public override void DidReceiveMemoryWarning ()
{
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
public void UpdateDisplay() {
DisplayValue.Text = $"{number[0]} {number[1]} {number[2]}";
}
}
}
Upvotes: 0
Views: 39
Reputation: 17382
Button
as you use it, is a type name, ie you are casting your sender to a variable click
of type Button
. But the respective type in Xamarin.iOS is called UIButton
See docs for details
UIButton click = (UIButton)sender;
Upvotes: 1