如何在 xamarin ios C# 中以编程方式触发 UIButton 的 TouchUpInside [英] How to fire TouchUpInside of UIButton Programmatically in xamarin ios C#
本文介绍了如何在 xamarin ios C# 中以编程方式触发 UIButton 的 TouchUpInside的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试以编程方式触发 Uibutton 的 touchupinside 事件.我怎样才能做到这一点 ?我尝试的代码使用 PerformSelector,但我收到此错误
I am trying to fire an touchupinside event of Uibutton programmatically. How can i do that ? The code I tried uses PerformSelector but i get this error
"Error MT4117: The registrar found a signature mismatch in the method
'VCPAckage2.ActivityViewController.TouchUpInsideEvent' - the
selector 'TouchUpInsideEvent:' indicates the method takes 1
parameters, while the managed method has 2 parameters. "
我想实现类似的东西
UIButton.FireEvent("TouchUpInsideEvent") - this will fire the TouchUpInsideEvent
UIButton.PerformSelector(new MonoTouch.ObjCRuntime.Selector ("TouchUpInsideEvent:"), null, 2000f);
这是代码
private void LoadFn()
{
UIButton btnSubmit = new UIButton(new RectangleF(0,0,View.Frame.Width,40));
btnSubmit.TouchUpInside+=TouchUpInsideEvent;
}
[Export("TouchUpInsideEvent:")]
private void TouchUpInsideEvent(object sender,EventArgs e){
float yy = AppConstants.ZeroVal;
if (FeedbackSubmittedReturnFlag == true) {
yy = ChildScrollView2.Subviews[1].Frame.Height+ChildScrollView2.Subviews[1].Frame.Y;
}
this.ParentScrollView.SetContentOffset (new PointF (View.Frame.Width, yy), false);
}
推荐答案
下面的代码片段就足够了
The following code snippet would be suffice
btnObj.SendActionForControlEvents(UIControlEvent.TouchUpInside);
必须从主线程调用
这篇关于如何在 xamarin ios C# 中以编程方式触发 UIButton 的 TouchUpInside的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文