简体   繁体   English

如何在Xcode 4.5中将.h和.m文件链接到新的ViewController?

[英]How to link .h and .m files to a new ViewController in Xcode 4.5?

Ok so I've been reading tutorials and surfing through StackOverflow and I haven't been able to get an answer to this question. 好的,所以我一直在阅读教程并通过StackOverflow进行浏览,但我还没有得到这个问题的答案。

I recently started developing iOS apps (this is my first one). 我最近开始开发iOS应用程序(这是我的第一个)。 I have a Tab Bar Controller and from there 5 different ViewControllers. 我有一个标签栏控制器,从那里有5个不同的ViewController。 As a default, it comes with FirstViewController and SecondViewController that I am able to modify their views in the StoryBoard and that I have them working "fine" for now. 作为默认,FirstViewController和SecondViewController附带了它们,它们能够在StoryBoard中修改它们的视图,并且现在让它们“精细”工作。 Now my question is how do I connect the other 3 missing ViewControllers to their respective .h and .m files? 现在我的问题是如何将其他3个缺少的ViewController分别连接到它们各自的.h和.m文件? I tried creating a new Objective-C class with XIB user interface but I was not able to connect that XIB file to the main Tab Bar controller in the MainStoryboard.storyboard so I think I am missing something. 我尝试使用XIB用户界面创建一个新的Objective-C类,但无法将该XIB文件连接到MainStoryboard.storyboard中的主Tab Bar控制器,所以我认为我丢失了一些东西。

Any help would be greatly appreciated! 任何帮助将不胜感激!

Don't mix XIBs and storyboards. 不要将XIB和情节提要混在一起。 All you have to do is to create classes (declared in h and m files) that inherit from UIViewController without XIB files and specify the class name in the storyboard's object inspector. 您要做的就是创建从UIViewController继承而没有XIB文件的类(在h和m文件中声明),并在情节提要的对象检查器中指定类名称。 The "link" to the files is by referencing the class name in the inspector. 通过在检查器中引用类名称来指向文件的“链接”。

在此处输入图片说明

Answer by Stavash is actually correct but u need to do something more. Stavash的回答实际上是正确的,但您需要做更多的事情。

You have to link the view property to the referencing outlet of the corresponding file. 您必须将view属性链接到相应文件的引用出口。

After linking the class name to the xib do the following. 将类名链接到xib后,请执行以下操作。

In xib file select the view controller -> in connections inspector -> drag and connect the view property to the view in xib. 在xib文件中,选择视图控制器->在连接检查器中->拖动并将view属性连接到xib中的视图。

I hope this will help. 我希望这将有所帮助。

基本上是从对象库中添加一个新的ViewController,将其自定义类设置为您的视图控制器的类(ThirdViewController),最后将一个关系segue从您的选项卡栏控制器拖到这个新的视图控制器,这会将它嵌入到选项卡栏中。

暂无
暂无

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

相关问题 在Story Board中为2个View控制器使用相同的ViewController h和m文件 - Using the same ViewController h and m files for 2 View controllers in Story Board 如何获得生成的* .m / *。h文件以在XCode4中识别以进行编译等? - how to get generated *.m/*.h files to be recognized in XCode4 for compilation etc? iOS Xcode-一组h / m文件中有多个自委托? - iOS Xcode - Multiple self delegates in single set of h/m files? 在.mm文件中找到的C ++标准库,在.h文件中找不到(Xcode 4.5 LLVM GCC 4.2) - C++ Standard Library found in .mm files but not in the .h (Xcode 4.5 LLVM GCC 4.2) 在ViewController.m中,如何通过字符串访问ViewController.h中声明的属性? - In ViewController.m, how can I access a property declared in ViewController.h by a string? 如何在新的XCode 4.5 GM的模拟器中设置iPhone 5? - How can I set the iPhone 5 in simulator in the new XCode 4.5 GM? 如何从Storyboard生成.m / .h文件? - How to generate .m/.h files from Storyboard? * .xib,*。m和* .h文件如何关联? - How are *.xib, *.m and *.h files related? 在Xcode中使用TabController模板-如何将对象链接回ViewController而不是TabController? - Using TabController Template in Xcode - How to link objects back to the ViewController instead of TabController? 我在情节提要中的视图控制器将无法连接到viewcontroller.h文件或.m - My view controller in storyboard will not connect to the viewcontroller.h file or the .m
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM