locked
IOS UIMenuController UIMenuItem, how to determine item selected with generic selector method RRS feed

  • Question

  • User392750 posted

    how to know the selected item with generic selector method in Xamarin.iOS

    var _menu = UIMenuController.SharedMenuController; BecomeFirstResponder(); var iterm = new UIMenuItem("John", new ObjCRuntime.Selector("MenuItemAction:")); _menu.MenuItems = new[] { iterm }; _menu.SetTargetRect(new CGRect(10, 10, 100, 100), _nativeControl); _menu.MenuVisible = true;

    [Export("MenuItemAction:")] private void MenuItemAction(UIMenuController controller) { // how to know the select

    Thursday, December 31, 2020 1:31 PM

Answers

  • User369978 posted

    It seems the only solution is to create multiple function with corresponding menuItem .

    ``` var iterm = new UIMenuItem("John", new ObjCRuntime.Selector("Action1:")); var iterm2 = new UIMenuItem("Cole", new ObjCRuntime.Selector("Action2:"));

    [Export("Action1:")] private void Action1(UIMenuController controller) {}

    [Export("Action2:")] private void Action2(UIMenuController controller) {}

    ```

    I tried to override the function with method methodSignatureForSelector and forwardInvocation , refer to the solution : , but it no luck , because Xamarin.iOS does not provide the API , check this issue : https://xamarin.github.io/bugzilla-archives/59/5954/bug.html .


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, January 1, 2021 3:21 AM