Trouble with referencing outlets in XCode with Xamarin.iOS

Robert Spencer 1 Reputation point
2021-02-19T09:25:19.62+00:00

I'm having trouble creating a custom UIView that contains a label, seeing as iOS Designer has disappeared from latest Visual Studio. What I've tried so far: In Visual Studio, I create a new View called 'CustomView', that generates a Xib to be opened in Xcode. I then create 2 new files in Visual Studio, which are the 2 partial classes for the UIView code behind (CustomView.cs & CustomView.designer.cs). I have written these correctly so that when I open the CustomView.xib, I set the file's owner to CustomView, and I can then in my app code do something like 'NSBundle.MainBundle.LoadNib("CustomView", this, null);' and add the View to a ViewController. This all works fine, although any advice on an easier way to setup a custom view would be appreciated. Just entering the name of the class in the old Ios Designer generated the code behind automatically for me, would be great to do that again.

My issue comes when trying to create an outlet for a label inside of CustomView.xib. I have tried dragging the label into just the .m file, or just the .h file of CustomView, and going back to CustomView.designer I can see that the label has been added as an outlet in both scenarios. However, when I run the application, I get an NSUnknownKeyException - this class is not key value coding-compliant for the key "CustomView Label".

I've tried loads of different ways to add the label as an outlet, and nothing seems to work. Could anyone enlighten me on what I'm missing, and or the correct approach on creating custom views with XCode? Any advice would be greatly appreciated! Thank you Rob

Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.