MonoTouch - 将UIActionSheet添加到我的ViewController顶部导航栏中

问题描述:

我有以下UIActionSheet。 如何将其添加到我的顶部导航栏? 最好是最右边的按钮。MonoTouch - 将UIActionSheet添加到我的ViewController顶部导航栏中

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

您可以使用ShowFrom方法显示ActionSheet。

特别是,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); 
    } 

https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CustomerManagement/CustomerManagement/CustomerManagement.Touch/Views/CustomerView.cs#L67