我试图通过在 ViewWillAppear() 函数中以编程方式调用按钮来伪造单击按钮的行为。
onclick 函数是在我的 ViewDidLoad() 中定义的,您可以看到我正在尝试使用执行选择器来手动调用按钮。
该按钮似乎没有运行。有任何想法吗?
public override void ViewDidLoad()
{
base.ViewDidLoad();
idButtonScanLoad.TouchUpInside += async (sender, ea) =>
{
System.Console.WriteLine("Scan button pressed");
};
}
[Export("TouchUpInsideEvent:")]
private void TouchUpInsideEvent(NSObject sender)
{
Console.WriteLine("yay!");
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
this.PerformSelector(new ObjCRuntime.Selector("TouchUpInsideEvent:"), this as NSObject, 10f);
}
这是答案,您应该从 ViewDidLoad 方法中调用它。
myButton.SendActionForControlEvents (UIControlEvent.TouchUpInside);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)