如何在uitableviewcell ios xamarin中创建小任务栏

时间:2017-01-12 07:13:36

标签: ios iphone xamarin

当按下消息时,如何在uitableviewcell中创建小任务栏(回复,复制,转发和删除),如whatsapp? enter image description here

2 个答案:

答案 0 :(得分:0)

" UIMenuController"与" menuItems:"将对您的自定义操作有用。

Apple文档链接:https://developer.apple.com/reference/uikit/uimenucontroller

答案 1 :(得分:0)

感谢Ios开发人员的指导..我已经使用了" UIMenuController",但此菜单未显示。

我的代码:

    [Export("LongPressMethod:")]
    public void LongPressMethod(UILongPressGestureRecognizer gestureRecognizer)
    {
        if (gestureRecognizer.State == UIGestureRecognizerState.Began)
        {
            var menuController = UIMenuController.SharedMenuController;
            var copyMenuItem = new UIMenuItem("copy", new ObjCRuntime.Selector("CopyRow"));
            var pasteMenuItem = new UIMenuItem("paste", new ObjCRuntime.Selector("PasteRow"));
            var location = gestureRecognizer.LocationInView(bc);
            bc.BecomeFirstResponder();
            menuController.MenuItems = new[] { copyMenuItem, pasteMenuItem };
            menuController.SetTargetRect(new CGRect(location.X, location.Y, 100, 100), bc);
            menuController.SetMenuVisible(true, true);

        }
    }

    [Export("CopyRow:")]
    void Row(UIMenuController controller)
    {
        // do something
    }

    [Export("PasteRow:")]
    void PasteRow(UIMenuController controller)
    {
        // do something
    }