I will be taking down this video this weekend and replacing it. Sure, you can do it this way, but it is so much easier to do it right! Here is an response to someone asking me about this tutorial...(I will be creating a new tutorial to replace this)...it is *SO* easy to share data between xibs...
--- here is my email to the guy ----------
Well, I've been putting off doing a tutorial showing two different approaches, I was going to do it this weekend. I've been pressed for time.
Okay, so are all three Xibs loading each other from interface builder or programatically?
I.E. are you doing something similar to this? This is programatically..... (NOT HOW THE TUTORIAL DOES IT)
RSSFeedDetailViewController * detail = [[RSSFeedDetailViewController alloc] initWithNibName:@"RSSFeedDetailViewController" bundle:nil];
RSSItem * myRSSItem = [[RSSItem alloc] init];
myRSSItem.moreURL = theUrl;
myRSSItem.image = theImage;
myRSSItem.videoURL = theVideo;
myRSSItem.audioURL = theAudio;
myRSSItem.description = theDesc;
myRSSItem.title = theTitle;
detail.myRSSItem = myRSSItem;
detail.myDisplayedProgram = self.myDisplayedProgram;
[self.navigationController pushViewController:detail animated:YES];
[detail release];
What I am doing is loading the xib programatically, creating a Model object, setting its variables, and then setting a property in the viewcontroller that points the the RSSItem. In the view controller's viewDidLoad method I then initialize the view according to its newly set RSSItem. This is the way to share data between views. *** BUT NOTE *** this is not the Interface Builder way illustrated in the tutorial.
Oh, and if you really want to separate viewcontrollers, have an external "view loader" class that handles loading views...that way viewcontrollerA never refers to viewControllerB...only the shared data class. Total separation.
-------------------------
Now, if you are using one of the templates, and not using code at all to load the view, then there is a magical IB trick...
Are you creating a mainwindow, then setting up tabs or a navigationcontroller, and then having it refer to viewcontrollers in other xibs? If so, then this is going to surprise you.
1. create your model class.
2. drag an object from the library to the mainwindow.xib project window
3. change the object's class to your model class
4. have all view controllers have an IBOutlet that references the object
5. wire up all the view controllers ***To the object in the mainwindow.xib.
6. Presto, all view controllers are sharing the same data object...
A sample project is attached based on the Tabs Template. The important thing is to remember to create an iboutlet in each viewcontroller and then wire it up to the object in the mainwindow.xib that way they are all sharing the same object. To initialize, simply use the viewDidLoad (or viewDidAppear like I do in the example) to get the values from the shared object and initialize the individual views.
In your case, you can have the first two views set appropriate values in the dataobject when the user is done entering the text, or you could set it on the viewWillDissapear method....since all three views share the same data object, that data is available in the next view.
I am extremely embarrassed I didn't show this in a tutorial and even more embarrassed I left it out of my book! It is so easy.
Like I said, I will have a tutorial soon....and remember, this is for when your setting up stuff using interface builder. If using code to load nibs, just do what I do above.
And if you are writing a complex application, with many views, then for heaven's sake, don't load xibs using IB, use code!!
Thanks,
James A. Brannan
iPhone SDK: A Beginner's Guide