c# - 如何在 xamarin ios C# 中以编程方式触发 UIButton 的 TouchUpInside

标签 c# ios xamarin.ios uibutton xamarin

我正在尝试以编程方式触发 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/

相关文章:

C# - 使用 MySql 数据库填充 ComboBox 时出现意外结果

windows-phone-7 - MvvmCross 定位 : switch at runtime

c# - 如何在 Dapper .Query<>() 中添加新的 PropertyType

c# - 将鼠标悬停在通知图标上显示文本

ios - 在 Xamarin.iOS 上使用 Mvvm-Light 设置命令后,您可以断开命令吗

ios - 无法使用核心数据持久删除记录

iphone - 使用 OCunit 在 iOS 上测试异步代码

ios - 升级后MonoTouch链接库编译问题

ios - 单点触控 : button not visible

c# - ElasticSearch C# Nest 使用 5.1 获取热门词