MonoTouch - how to override static UICollectionVie

2019-05-18 09:36发布

问题:

I have the opposite problem to this question

Unlike UIView, where monotouch has omitted the definition of the static method layerClass, presumedly to allow you to define it in a subclass, layoutAttributesClass is defined in UICollectionViewLayout and I have no idea how to override it in my subclass.

I've tried...

    [Export ("layoutAttributesClass")]
    public static Class LayoutAttributesClass {
        get { return new Class(typeof(MyClass)); }
    }

... but this is never called.

回答1:

This actually works, don't let the hides inherited member warning throw you off (like I did) -you can use the new operator to get rid of it and it still works.

The real problem if you go down this route is implementing copyWithZone on your UICollectionViewLayoutAttributes subclass as support for this is fairly lacking in Xamarin