C# MonoTouch-将UIActionSheet添加到my ViewController的顶部导航栏

C# MonoTouch-将UIActionSheet添加到my ViewController的顶部导航栏,c#,xamarin.ios,uiactionsheet,C#,Xamarin.ios,Uiactionsheet,我有下面的行动表。 如何将其添加到顶部导航栏? 最好是最右边的按钮 var sheet = new UIActionSheet (""); sheet.AddButton ("Discard Picture"); sheet.AddButton ("Pick New Picture"); sheet.AddButton ("Cancel"); sheet.CancelButtonIndex = 2;

我有下面的行动表。 如何将其添加到顶部导航栏? 最好是最右边的按钮

var sheet = new UIActionSheet ("");
            sheet.AddButton ("Discard Picture");
            sheet.AddButton ("Pick New Picture");
            sheet.AddButton ("Cancel");
            sheet.CancelButtonIndex = 2;

            // Dummy buttons to preserve the space for the UIImageView
            for (int i = 0; i < 4; i++) {
                sheet.AddButton("");
                sheet.Subviews[i+4].Alpha = 0; // And of course it's better to hide them
            }

            var subView = new UIImageView();
            subView.ContentMode = UIViewContentMode.ScaleAspectFill;
            subView.Frame = new RectangleF(23,185,275,210);

            // Late Steve Jobs loved rounded corners. Let's have some respect for him
            subView.Layer.CornerRadius = 10; 
            subView.Layer.MasksToBounds = true;
            subView.Layer.BorderColor = UIColor.Black.CGColor;
            sheet.AddSubview(subView);

            NavigationController.Add(sheet);
var表=新的UIActionSheet(“”);
sheet.AddButton(“放弃图片”);
sheet.AddButton(“选择新图片”);
sheet.AddButton(“取消”);
sheet.CancelButtonIndex=2;
//保留UIImageView空间的虚拟按钮
对于(int i=0;i<4;i++){
页。添加按钮(“”);
sheet.subview[i+4].Alpha=0;//当然最好隐藏它们
}
var subView=新的UIImageView();
subView.ContentMode=UIViewContentMode.ScaleSpectFill;
框架=新矩形F(23185275210);
//已故的史蒂夫·乔布斯喜欢圆角。让我们尊重他吧
子视图.Layer.CornerRadius=10;
subView.Layer.MasksToBounds=true;
subView.Layer.BorderColor=UIColor.Black.CGColor;
sheet.AddSubview(子视图);
导航控制器。添加(表);

您可以使用
ShowFrom
方法显示操作表

特别是,
ShowFromToolbar
从顶部工具栏按钮显示工作表

下面是一个示例,根据您使用的是平板电脑还是手机,以不同的方式显示工作表:

    void ActionMenu()
    {
        //_actionSheet = new UIActionSheet("");
        UIActionSheet actionSheet = new UIActionSheet (
            "Customer Actions", 
            null, 
            "Cancel", 
            "Delete Customer",
             new string[] {"Change Customer"});

        actionSheet.Style = UIActionSheetStyle.Default;
        actionSheet.Clicked += delegate(object sender, UIButtonEventArgs args) {
            switch (args.ButtonIndex)
            {
                case 0: DeleteCustomer(); break;
                case 1: ChangeCustomer(); break;
            }
        };

        if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            actionSheet.ShowFromToolbar(NavigationController.Toolbar);
        else
            actionSheet.ShowFrom(NavigationItem.RightBarButtonItem, true);
    }