views:

27

answers:

1

I am trying to build my first iphone app. first i finish with my app logic whitch contain DataLogic class that have all my arrays. and another 2 classes

then i build my appGUI that contain 2 views. SearchViewClass and ResultViewClass now my problem is how to connect to logic to the GUI. the instance of DataLogic is on my AppDelegate class and i need that the two GUI classes will be able to accsess to this instance but i dont know who to accsess to the instances in the AppDelegate class from the GUI classes?

i also didnt see where the app initialize the GUI classes?? so where is the GUI classes instance??

A: 

You use the MVC (Model-View-Controller) design pattern. It should be called the Model-Controller-View pattern because the controller mediates between the model and the view.

In your case the DataLogic class is your model. The views are controlled by a paired view controller object which is an instance or a subclass of UIViewController. Depending on the app, there are many different ways to relate the view controllers to each other, their views and the model.

The easiest to understand would be the Navigation Based App in the Xcode Template projects. It has no data model object but it does have a navigation controller and a RootViewController class its paired view defined in the RootViewController.xib. The rootViewController is an instance of the RootViewController subclass of UIViewController (Usually, RootViewController>UITableViewController>UIViewController.)

In your case, you would add a property to the RootViewController to hold a reference to your DataLogic class. In the app delegate's application:didFinishLaunching: method you would initialize your DataLogic instance and then set the RootViewController's property to the DataLogic instance.

Now the RootViewController instance connects to the DataLogic instance. When the navigation controller pushes the RootViewController instance on to the navigation stack, the RootViewController instance's view (assigned in the nib file) loads. The RootViewController instance then takes data from the DataLogic instance and populates the UI elements in the view. When the users enters data into the UI the controller takes the data from the UI elements and puts them in the DataLogic instance.

The controllers tie the model to different views. The views never directly communicate with the model and vice versa. Many different views can use the same model and display different attributes of the model merely by writing a new controller to connect the two together.

TechZen
maybe you can help me with code?how to accsess to the rootviewcontroller?i dont have RootViewController I have FirstViewController.
Amir
I have Tab Bar application and i want from all of the tab windows to be able to accsess to the DataLogic.i didnt find how to use the RootViewController maybe you can help me with code? how to accsess to the rootviewcontroller? i dont have RootViewController I have FirstViewController.
Amir
Apple can help you with code, that's what the iOS Reference Library is for :) Link to a good one to start with: http://developer.apple.com/iphone/library/samplecode/SimpleDrillDown/Introduction/Intro.html
iWasRobbed
Also, another one with tab bar: http://www.youtube.com/watch?v=LBnPfAtswgw
iWasRobbed
Tabbar is the same ideas as a navigation controller. Each view in the tabbar has a custom controller class. You create a property of each controller class that holds a reference to the DataLogic object.
TechZen
Look at the Tabbar Application template in Xcode. It shows how the part relate minus the Datalogic object.
TechZen