因为它还没有(还)可以使用Storyboard来生成类和粘合代码.我有想法自己编写F#类并自己粘贴.
所以我写了这个Storyboard命名空间的加载
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
和以下控制器类
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!")
然后我创建了故事板(见附图).
AND – 一切都被加载,故事板工作正常 – 一个例外:ViewDidLoadnever被调用.显然我没有成功连接我的手动编码控制器.
有没有人知道如何做到这一点?
解决方法
我找到了答案.而不是创建没有参数的控制器
[<Register("HomeController")>] type HomeController() = inherit UIViewController()
必须创建一个带指针的控制器,并使用该指针初始化基本控制器.
[<Register("HomeController")>] type HomeController(handle:IntPtr) = inherit UIViewController(handle)
使用视图控制器附加视图上的控件(例如,附加名为“Clicker”的按钮)
[<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