问题
Now I want to implement some functions in my xamarin.iOS projecs .
I have found the solution but implemented in Objective-C.And it used the keyword @selector(...)
. I found this issue as refer.However,as @theB said,use the dynamic type. Of course this means that type safety is only enforced at runtime, and you may incur some performance penalties.SO is there a better way to implement it? Any suggestion is welcome.Thanks!
回答1:
@selector
is available in xamarin.iOS. It is included in the namespace ObjCRuntime
.For example ,you can bind click action for a UIButton
.Just like in Objective-C.
using ObjCRuntime;
. . .
UIButton button = new UIButton()
{
//. . .
};
button.AddTarget(this, new Selector("ButtonClickAction:"),UIControlEvent.TouchUpInside);
[Export("ButtonClickAction:")]
public void ButtonClickAction(UIButton sender)
{
// . . .
}
[Export("ButtonClickAction:")]
It is important.Members with an [Export]
, making it possible for Objective-C to access them.For more details you can refer the docuemnt.
来源:https://stackoverflow.com/questions/52659151/how-to-use-selector-in-xamarin-ios