gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:03 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com