IPhone MVC. Model Issues

I am new to programming, programming iphone apps in particular. After reading a bunch of MVC, I decided to try it in a small application. As for my understanding, MVC works as follows:

Model: data, data processing, data extraction. ViewController: formats data from a model (NSDate for a specific style), etc. View: actual gui.

If this is truly the correct formulation of the basic theory of MVC, my confusion is how the data is transferred between the model, VC, and view. Example: if I make calls to twitter and receive data in the model, how I (correctly) pass this information to VC for further work. I know that between VC and View IBOutlets are mainly used. The model is my real problem.

In my last application, I made the NSString variable in the application's delta so that I could access this data from any class. However, I read that this is not the best approach when the application becomes complex, because the delegate is responsible for starting, terminating the application, and not storing data.

I read about delegation methods, singleton's, NSNotification (which I used to call methods in other classes). The problem is that I really don’t understand how to use these methods to transfer data from the model to other views.

Please let me know if my question is unclear.

+4
source share
2 answers

If you are thinking of reuse, the main components that can be reused are your model objects and view objects. They can be transferred to different applications and used properly. Your view controller is what is truly specific to your application and where most of the application logic lies.

So, in your example, you may have a twitter object that possibly stores information and tweets from the user. You will create this class with all its functions separately in your own .h and .m files. Then, in your view controller, create an instance of the twitter class with the data to be extracted, and start using it from the view controller.

Your view controller actually retrieves the data, but your model object is the one that supports the data. Thus, you can transfer model data with your twitter object to other view controllers.

+3
source

The control over the application is in the controller, therefore it is an object that will retrieve or save stored data, update views with this data and process various events. Think of it as glue between the model and the look!

For example, if you want to click a button to open a new modal view, you must handle this event in your view controller. In the method that answers the pressed button, you create or access a new view controller and present it using presentModalViewController: animated :. If this new view and controller needs data that your current controller has access to, you can set the property in the new controller to access the object.

+1
source

All Articles