如何检索按钮(MonoTouch)上的TouchUpInside返回



信息

我正在使用Xamarin Studio和Xcode。

我的两个按钮"IncreaseButton"和"ReductionButton"都将其发送的事件"TouchUpInside"附加到我的IBAction"buttonClick"上。

下面的代码

将在构建部分无效按钮单击函数时产生 2 个错误;但是,我的问题是我怎么能不产生这 2 个错误,同时实现我在下面的代码中要实现的目标(如果这有任何意义的话)。

谢谢。

using System; 
using System.Drawing; 
using MonoTouch.Foundation; 
using MonoTouch.UIKit;
namespace Allah
{
public partial class AllahViewController : UIViewController
{
    protected int clickCount;
    public AllahViewController () : base ("AllahViewController", null)
    {
    }
    public override void DidReceiveMemoryWarning ()
    {
        // Releases the view if it doesn't have a superview.
        base.DidReceiveMemoryWarning ();
        // Release any cached data, images, etc that aren't in use.
    }
    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        this.IncreaseButton.TouchUpInside += (sender, e) => {
            this.clickCount++;
        };
        this.DecreaseButton.TouchUpInside += (sender, e) => {
            this.clickCount--;
        }; 
        // Perform any additional setup after loading the view, typically from a nib.
    }
    partial void buttonClick (NSObject sender)
    {
        if (this.IncreaseButton.TouchUpInside == true)
        {
            this.CountLabel.Text = clickCount.ToString();
        }
        if (this.DecreaseButton.TouchUpInside == true)
        {
            this.CountLabel.Text = clickCount.ToString();
        }
    }
}}
每个

视图(包括UIButton)作为整数标记属性,您可以设置为将多个视图彼此区分开来。 如果只想为按钮使用单个事件处理程序,则可以使用 Tag 属性。

IncreaseButton.Tag = 1;
DecreaseButton.Tag = -1;
partial void ButtonClick(NSObject sender)
{
  clickCount = clickCount + ((UIButton)sender).Tag;
  this.CountLabel.Text = clickCount.ToString();
}
你可以

这样写:

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    // Perform any additional setup after loading the view, typically from a nib.
}
partial void decreaseButtonClick (NSObject sender)
{
    clickCount--;
    this.CountLabel.Text = clickCount.ToString();       
}
partial void increaseButtonClick (NSObject sender)
{
    clickCount++;
    this.CountLabel.Text = clickCount.ToString();       
}

最新更新