如何创建故事板并将其 link 到现有的 UIViewController?
How to create a storyboard and link it to an existing UIViewController?
我是 Xamarin.iOS 平台的新手。
我创建了一个空的 Xamarin.iOS 项目,然后创建了我的主 UIViewController,即 UIViewController1,然后在 AppDelegate.cs:
// If you have defined a root view controller, set it here:
var view1 = new UIViewController1();
Window.RootViewController = view1;
// make the window visible
Window.MakeKeyAndVisible();
在 UIViewController1 中,我对所有标签和按钮等进行了硬编码。像这样:
var frame = new CGRect(10, 10, 300, 30);
var Label = new UILabel(frame);
View.AddSubView(Label);
但是现在确认一切正常后,我想为我的 UIViewController1 创建一个情节提要并将所有元素移到上面以供将来维护,所以在创建之后一个空的 Storyboard 如何 link 它到我当前的 UIViewController1?
我找到的其他解决方案都行不通。我得到的只是一个空白的白屏。
打开你的空 Storyboard,在左侧 window 你会看到工具箱(如果你没有看到它,Ctrl + Alt + X 打开它)。 Select一个ViewController
然后把它放在故事板上。
在这里你会看到一个只有一个 ViewController 的 Storyboard,比如:
点击 ViewController 左下角的黄色按钮。在属性window我们可以选择它的Class,点击向下箭头select:
这样,我们就把ViewController绑定到了UIViewController1
。但是我们还需要在这个 class:
中创建一个初始方法
public UIViewController1 (IntPtr handle) : base(handle)
{
}
如果您想使用 Storyboard 作为您的初始 Window,请打开您的 info.plist、select Storyboard 的主界面。然后在 FinishedLaunching()
中删除所有关于初始化 Window
:
的代码
//var view1 = new UIViewController1();
//Window.RootViewController = view1;
// make the window visible
//Window.MakeKeyAndVisible();
此外,我们应该使用 UIStoryboard.FromName("StoryboardName", null).InstantiateViewController("ViewControllerID");
而不是用 var view1 = new UIViewController1();
构造 ViewController。这个ViewControllerID可以设置在属性window我post上面叫Storyboard ID;
我是 Xamarin.iOS 平台的新手。
我创建了一个空的 Xamarin.iOS 项目,然后创建了我的主 UIViewController,即 UIViewController1,然后在 AppDelegate.cs:
// If you have defined a root view controller, set it here:
var view1 = new UIViewController1();
Window.RootViewController = view1;
// make the window visible
Window.MakeKeyAndVisible();
在 UIViewController1 中,我对所有标签和按钮等进行了硬编码。像这样:
var frame = new CGRect(10, 10, 300, 30);
var Label = new UILabel(frame);
View.AddSubView(Label);
但是现在确认一切正常后,我想为我的 UIViewController1 创建一个情节提要并将所有元素移到上面以供将来维护,所以在创建之后一个空的 Storyboard 如何 link 它到我当前的 UIViewController1?
我找到的其他解决方案都行不通。我得到的只是一个空白的白屏。
打开你的空 Storyboard,在左侧 window 你会看到工具箱(如果你没有看到它,Ctrl + Alt + X 打开它)。 Select一个ViewController
然后把它放在故事板上。
在这里你会看到一个只有一个 ViewController 的 Storyboard,比如:
点击 ViewController 左下角的黄色按钮。在属性window我们可以选择它的Class,点击向下箭头select:
这样,我们就把ViewController绑定到了UIViewController1
。但是我们还需要在这个 class:
public UIViewController1 (IntPtr handle) : base(handle)
{
}
如果您想使用 Storyboard 作为您的初始 Window,请打开您的 info.plist、select Storyboard 的主界面。然后在 FinishedLaunching()
中删除所有关于初始化 Window
:
//var view1 = new UIViewController1();
//Window.RootViewController = view1;
// make the window visible
//Window.MakeKeyAndVisible();
此外,我们应该使用 UIStoryboard.FromName("StoryboardName", null).InstantiateViewController("ViewControllerID");
而不是用 var view1 = new UIViewController1();
构造 ViewController。这个ViewControllerID可以设置在属性window我post上面叫Storyboard ID;