简体   繁体   中英

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.

I recently started developing iOS apps (this is my first one). I have a Tab Bar Controller and from there 5 different ViewControllers. 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. Now my question is how do I connect the other 3 missing ViewControllers to their respective .h and .m files? 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.

Any help would be greatly appreciated!

Don't mix XIBs and storyboards. 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. 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.

You have to link the view property to the referencing outlet of the corresponding file.

After linking the class name to the xib do the following.

In xib file select the view controller -> in connections inspector -> drag and connect the view property to the view in xib.

I hope this will help.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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