PDA

View Full Version : ViewController from Xib to Storyboard




at0m87
Mar 3, 2012, 12:47 PM
In my XIB Sample code, the file owner is TrainViewController and WritingViewController is added into the XIB as shown in the picture below. and the IBOUTLET "Sign" from TrainViewController is connected to WritingViewController. Note: i annotated wrongly on the picture should be TrainViewController instead of TrainingViewController.

https://lh5.googleusercontent.com/-lSqH-gAV738/T0dnkC2qOmI/AAAAAAAAAhc/lSjUiBlU3_g/s1063/XIB.png

So in my Storyboard which i am trying to replicate the same code, i created two view controller scene which is TrainViewController as well as WritingViewController. I am unable to link the IBOUTLET "Sign" to WritingViewController as i believe they are not "link" like in the XIB sample code where the WritingViewController is in the same XIB as the TrainViewController.

https://lh5.googleusercontent.com/-6R-VbixrA0w/T0dnoz5zssI/AAAAAAAAAhk/HInVDUHgoRk/s963/Storyboard.png

what should i do?



brontosaurus
Mar 3, 2012, 05:49 PM
In storyboard, are you trying to connect a UI object in one view controller (scene) to another view controller (scene) using an outlet? If so, I think you might need to look into creating a segue instead.

at0m87
Mar 4, 2012, 03:31 AM
In storyboard, are you trying to connect a UI object in one view controller (scene) to another view controller (scene) using an outlet? If so, I think you might need to look into creating a segue instead.

in the XIB, there is a trainViewController which declared "IBOutlet writingViewController *sign" and this IBOutlet is connected to the writingViewController view controller in the same XIB.

What i think it is actually doing is to create a link between the two controllers.

in parts of the codes of the trainViewController.m
[sign.signArray removeAllObjects];
sign.drawImage.image=nil;
sign.writeTimer=nil;

signArray, drawImage and writeTimer are all declared in the writingViewController.h

to also note that UIImageView *drawImage is declared in writingViewController.h but it is physically on the the trainViewController's view controller.

how should i achieve this same concept in the storyboard method. i know i can't connect the IBOutlet from trainViewController to writingViewController. segue? how should i do that?

brontosaurus
Mar 4, 2012, 01:05 PM
I'm trying to learn this stuff too.

Segues are what define the transitions between view controllers (or scenes). You already have a couple of segues in your app already. Visually, they are represented by arrows between your scenes in the storyboard canvas.

You create segues in storyboard by control-dragging from a UI object or a view controller to another view controller. Then in the pop-up that appears, you choose the type of segue. For a navigation hierarchy, for example, you would choose a push segue.

As far as the outlet business goes, don't declare sign as an outlet; instead just declare it as a regular property:
@property (strong, nonatomic) writingViewController *sign;

How is the train view controller related to the rest of your app? Is the train view controller already a part of a navigation hierarchy? And how do you want the train view controller to present the writing view controller?