Unable to access page controls when changing a Xamarin.iOS controller from UIViewController into a PageRenderer
315 Репутация автора
I am moving a Xamarin iOS project into Xamarin Forms, working in Visual Studio 2017.
In my iOS project i have a controller that has its components (UIWebView, UIImageView among others) in a storyboard. I have changed so that my controller now inherit fom
PageRenderer instead of
UIViewController and i use
ExportRenderer to reference it from within Forms and that part works just fine.
My issue is that the components that are used in my controller that are declared in the controller.designer.cs file are now all null when I try to use them in the controller.cs file, I guess I am missing some step to actually get the component instances set.
Any hint on what to try next would be appreciated.Автор: Mårten Источник Размещён: 08.11.2017 11:06
6724 Репутация автора
When you define a UI using a storyboard, when the system deserializes the XML the system takes care of creating new instances of all the objects you've defined and "wiring them together" in terms of adding them to the
UIViewController or their parent
UIView objects or what-have-you.
If you want to port from that model to building the UI in code, you have to recreate that process, instantiating the instances and building the view-controller and view hierarchies. (If you defined transitions and so forth in the storyboard, you'll have to programmatically instantiate and wire them together as well.)
PS: The Storyboard deserialization process uses constructors that take an
IntPtr, while when you do it in code, you'll most likely use a default ctor. If there's any custom code inside your existing
IntPtr ctors, you'll need to move that into the constructor you use.