Fitzy
Fitzy

Reputation: 1889

creating IBOutlets in ViewController.h from another UIViewController's .xib file

I am currently reading 'Beginning iOS 5 Games Development: Using the iOS SDK for iPhone, iPad and iPod Touch' by Lucas Jordan. In this book, there is a section in where you are instructed to make a 'Rock, Paper, Scissors' game using a variety of UIViewControllers. My problem is that I cannot create an IBOutlet from the ViewController_iphone.xib (which, as the name suggests, is made for the iPhone) to the ViewController.h file that comes with every new project.

In ViewController_iPhone.xib I have created a UIView and set the file's owner of the .xib to ViewController_iPhone.xib. When i ctrl+click and try to link the view to ViewController.h, it simply does not give me the option to do so. When I change the file's owner to ViewController, it is not a problem to create IBOutlets in ViewController.h, however that is not the correct file's owner that will allow the program to work correctly.

I have downloaded the source code for the book, and the author of the book seemed to have no problems whatsoever creating the oultlets. I have compared my project to his and I can't seem to find what is wrong.

If anybody could help me, I would be very grateful. Thanks!

Fitzy

Upvotes: 0

Views: 746

Answers (2)

RonLugge
RonLugge

Reputation: 5184

The MVC model, Model-View-Controller model, isn't intended to have an action in one view touch the controller of another view. In InterfaceBuilder, you should only ever be able to attach actions to the controller for that specific view.

What you may want is some way to relay information from one view controller to another -- I tend to use delegates for that, but without knowing more about what you're doing, I don't know if that's the correct answer.

Upvotes: 0

sch
sch

Reputation: 27516

You should set the file owner to the name of the associated UIViewController which is ViewController in your case.

In general, if you set the file owner to XViewController, then you can only link IBoutlets to that view controller.

Upvotes: 1

Related Questions