How to fire TouchUpInside of UIButton Programmatically in xamarin ios C# -


i trying fire touchupinside event of uibutton programmatically. how can ? code tried uses performselector error

"error mt4117: registrar found signature mismatch in method  'vcpackage2.activityviewcontroller.touchupinsideevent' -  selector 'touchupinsideevent:' indicates method takes 1  parameters, while managed method has 2 parameters. " 

i want achieve

uibutton.fireevent("touchupinsideevent") - fire touchupinsideevent  uibutton.performselector(new monotouch.objcruntime.selector ("touchupinsideevent:"), null, 2000f); 

here's code

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

there's few different things above.

first, mt4117 correct. happens because [export] attribute specify selector method has 1 parameter (i.e. has 1 :) while managed method has 2 parameters (which default .net events). registrar spot such conditions , report errors.

second, performselector methods bindings on performselector:... selectors (most defined on nsobject protocol, not class). such have same limitations (e.g. number of arguments can handle).

third, there several ways call own code. easy 1 be, @jonathanpeppers suggested, directly call managed method when needed.

another 1 adjust code match both 1 , 2 requirements, e.g.

// assign 1 (two parameters) method .net event btnsubmit.touchupinside += touchupinsideevent; ... // call (one parameter) method selector any_nsobject.performselector (new selector ("touchupinsideevent:"), sender nsobject, 0f); ...  // have 2 parameters method call the(1 parameter) export'ed method private void touchupinsideevent (object sender, eventargs e) {     touchupinsideevent (sender nsobject); }  [export ("touchupinsideevent:")] private void touchupinsideevent (nsobject sender) {     console.writeline ("yay!"); } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -