How to use Xamarin Storyboard and F #

since it is (for now) impossible to use Storyboard to generate classes and glue code. I had an idea to write F # classes myself and make a gluing myself.

So I wrote this Storyboard namespace load

open System open MonoTouch.UIKit open MonoTouch.Foundation [<Register("AppDelegate")>] type AppDelegate() = inherit UIApplicationDelegate() member val window = null with get, set override this.FinishedLaunching(app, options) = this.window <- new UIWindow(UIScreen.MainScreen.Bounds) let Storyboard = UIStoryboard.FromName("MainStoryboard", null) this.window.RootViewController <- Storyboard.InstantiateInitialViewController() :?> UIViewController this.window.MakeKeyAndVisible() true module Main = [<EntryPoint>] let main args = UIApplication.Main(args, null, "AppDelegate") 0 

and the next controller class

 open System open System.Drawing open MonoTouch.UIKit open MonoTouch.Foundation [<Register("HomeController")>] type HomeController() = inherit UIViewController() override this.ViewDidLoad() = base.ViewDidLoad() System.Console.WriteLine("FOO!") 

Then I created a storyboard (see attached photos). Viewsproperties

And - everything loads, and the storyboard works fine - one exception: ViewDidLoadnever is called. Obviously, I was unable to install my manual encoded controller.

Does anyone have any ideas how to do this?

+6
source share
1 answer

I have found the answer. Instead of creating a controller without parameters

 [<Register("HomeController")>] type HomeController() = inherit UIViewController() 

You must create a controller with a pointer and initialize the base controller with this pointer.

 [<Register("HomeController")>] type HomeController(handle:IntPtr) = inherit UIViewController(handle) 

To connect controls to a view using a view controller (for example, attach a button named "Clicker")

enter image description hereenter image description here

need to add the following code to the view controller

 [<Register("HomeController")>] type HomeController(handle:IntPtr) = inherit UIViewController(handle) let mutable _Clicker = new UIButton() [<Outlet>] member this.Clicker with get() = _Clicker and set value = _Clicker <- value 
+8
source

Source: https://habr.com/ru/post/978994/


All Articles