简体   繁体   English

我是否需要iPhone和iPad故事板的多个视图控制器?

[英]Do I need multiple view controllers for the iPhone & iPad storyboards?

I'm still relatively unfamiliar with all the new features of iOS 5, and what I can do in Xcode now. 我还是比较熟悉iOS 5的所有新功能,以及我现在可以在Xcode中做些什么。 So, a good explanation would be appreciated. 所以,一个很好的解释将不胜感激。

I'm designed a single-view application and I have both an iPhone and iPad storyboard. 我设计了一个单视图应用程序,我有一个iPhone和iPad故事板。 I chose 'Single View Application' when I first started, so Xcode created a ViewController for me. 我刚开始时选择了“单视图应用程序”,因此Xcode为我创建了一个ViewController。 Both storyboards list this view controller as their own. 两个故事板都将此视图控制器列为自己的。

Back in iOS 4 the way that I linked button actions to my view controller was to Right-Click on the button on the nib, pick the action that I wanted, then drag it over into the view controller's '.h' file, which auto-created a method/property for me. 回到iOS 4,我将按钮操作链接到视图控制器的方法是右键单击笔尖上的按钮,选择我想要的动作,然后将其拖到视图控制器的'.h'文件中,该文件是自动的 - 为我创建了一个方法/属性。

I am confused about how to accomplish this now, since I have multiple storyboards but only one view controller. 我现在很困惑如何实现这一点,因为我有多个故事板但只有一个视图控制器。 Do I need to have multiple links for each button; 每个按钮是否需要多个链接; one for the button on the iPhone and one for the iPad? 一个用于iPhone上的按钮,一个用于iPad? Or is there a better way to accomplish what I am trying to do now? 或者有更好的方法来完成我现在要做的事情吗?

You do it the same way you did it in iOS4. 你这样做的方式与你在iOS4中的方式相同。 But obviously you never built an universal app there ;-) 但显然你从来没有在那里建立一个通用应用程序;-)

It's totally okay to have a single UIViewController class for two different nib files. 为两个不同的nib文件提供单个UIViewController类是完全可以的。 And if you use storyboards it's fine to use different storyboards and a single viewController too. 如果你使用故事板,也可以使用不同的故事板和单个viewController。

You can even use the same viewController for different scenes inside a single storyboard. 您甚至可以将同一个viewController用于单个故事板中的不同场景。

The connections to the viewController are saved in the nib or storyboard. 与viewController的连接保存在nib或storyboard中。 So you can't overwrite them while designing the other user interface. 因此,在设计其他用户界面时,您无法覆盖它们。

Open the iPhone storyboard, make your connections to actions and outlets. 打开iPhone故事板,与行动和销售点建立联系。 Then open the iPad storyboard and make totally independent connections. 然后打开iPad故事板并建立完全独立的连接。

In response to the first reply, I was under the impression that a view controller could only support two scenes in a storyboard layout. 在回复第一个回复时,我的印象是视图控制器只能支持故事板布局中的两个场景。 I say that because I found this thread . 我说是因为我找到了这个帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM