How to use a Custom iOS View(located in a referenced Class Library) in an Interface Builder file?

Hello,

I have two projects. The first one is the iOS-App which is referencing a class library with the target framework "Xamarin.iOS". In that class library I implemented a CustomView which inherits from UIView. I also registered it with the "Register" attribute.

So in the interface designer I get the prefilled information to use this class as custom class after I dragged the UIView to my ViewController. But when I run the app I get the following information: "Unknown class MyCustomView in Interface Builder file."

If I move the my CustomView from the class library project into my first project then it will run as expected.

Does someone know how to use a CustomView, which is located in a referenced class library, in an Interface Builder file?

Answers

  • DuaneCDuaneC CAMember ✭✭
    edited July 2016

    Hi,

    I think you need to Register the referenced CustomView class again (as a derived class) in the app code, for it to be exposed to Main.storyboard. In your class library, you can re-name the CustomView class to, e.g., MyCustomView1, to avoid a name collision when you register it, and then recompile the library. Then, you app code would look something like:

    using Foundation;
    using UIKit;
    using [referenced class library];
    
    namespace [app project namespace]
    {
        [Register ("MyCustomView")]
        public class MyCustomView : MyCustomView1
        {
            public MyCustomView ( IntPtr handle) : base (handle)
            {
    
            }
        }
    }
    

    where '[referenced class library]' and '[app project namespace]' are replaced with appropriate names.

    Hope that helps.

Sign In or Register to comment.