以编程方式触发UIButton的TouchUpInside

以编程方式触发UIButton的TouchUpInside

我正在尝试以编程方式触发Uibutton的touchupinside事件。我怎样才能做到这一点 ?我尝试的代码使用PerformSelector,但出现此错误

"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);
 }

最佳答案

下面的代码片段就足够了

btnObj.SendActionForControlEvents(UIControlEvent.TouchUpInside);

必须从主线程调用

关于c# - 如何在Xamarin iOS C#中以编程方式触发UIButton的TouchUpInside,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26883597/

10-10 09:33