2

我正在使用最新的Monotouch 5.2.4。作为我的开发的一部分,我试图改变Popover控制器的背景边界。按照苹果文档,这可以使用从UIPopoverBackgroundView类继承的自定义类进行管理。UIPopoverController的PopoverBackroundViewClass属性丢失

所以我建立了一个这样的类,如下

public class MyPopoverBackground : UIPopoverBackgroundView 
{ 
    public MyPopoverBackground() 
    { 
     UIImageView imgBackground = new UIImageView(); 
     UIImage img = UIImage.FromFile(@"SupportData/Popbg.png"); 
     img.StretchableImage(18,10); 
     imgBackground.Image = img; 
     this.AddSubview(imgBackground); 
    } 
} 

创建这个类之后,我想这个观点与弹出对象我在我的视图控制器关联。它的定义如下

UIPopoverController popup = new UIPopoverController(searchPage); 
popup.popOverBackroundViewClass = new MyPopoverBackground(); //This line throws compilation error 

上面代码的最后一行,其中分配happing抛出编译错误(“不包含定义..”)。

这是什么意思?这在Monotouch中是不被支持的(似乎在Objective-C中被支持,因为我在网上看到很多例子)?或者我错过了一些东西。

感谢您的帮助。

回答

3

好抓!它看起来像是一个绑定,目前从MonoTouch中缺少popoverBackgroundViewClass(iOS5中的新增功能)。

我会考虑实施它。如果你想填写一个错误报告http://bugzilla.xamarin.com,你会收到通知一旦完成(只是一个快速的错误报告与这个问题的链接就够了)。我也应该能够给你一个修补程序或解决方法。

UPDATE

在MonoTouch的5.3+(一旦释放),你就可以这样做:

popoverController.PopoverBackgroundViewType = typeof (MyPopoverBackgroundView); 

请注意,你不能创建自己的实例,因为它需要从做本地方(因此为什么你只告诉UIPopoverController要创建哪种类型)。

您还需要遵循UIPopoverBackgroundView的所有要求,这意味着要导出所需的选择器(因为它需要static方法,所以它比简单继承要复杂一点)。例如。

class MyPopoverBackgroundView : UIPopoverBackgroundView { 

     public MyPopoverBackgroundView (IntPtr handle) : base (handle) 
     { 
      ArrowOffset = 5f; 
      ArrowDirection = UIPopoverArrowDirection.Up; 
     } 

     public override float ArrowOffset { get; set; } 

     public override UIPopoverArrowDirection ArrowDirection { get; set; } 

     [Export ("arrowHeight")] 
     static new float GetArrowHeight() 
     { 
      return 10f; 
     } 

     [Export ("arrowBase")] 
     static new float GetArrowBase() 
     { 
      return 10f; 
     } 

     [Export ("contentViewInsets")] 
     static new UIEdgeInsets GetContentViewInsets() 
     { 
      return UIEdgeInsets.Zero; 
     } 
    } 
+0

感谢您的及时回复。正如你所提到的,我填补了一个错误。我很高兴看到SO被同一个产品团队密切关注和回应。保持.. – 2012-02-17 05:45:48