views:

41

answers:

1

Gentleones,

I've got a UIImageView that I have in a UIView. This particular UIImageView displays a PNG of a graph. It's important for this particular view controller and another view controller to know what the graph "looks like," i.e., the function described by the PNG graph. These other view controllers need to be able to call a "function" of some sort with the X value returning the Y value.

Please ignore the fact (from an outsider's perspective) that I could probably generate the graph programmatically.

So my questions are:

1 - Where should I put this function? Should it go in one view controller or the other, or should it go in its own class or main or...?

2 - Should it be an object in some way? Or should it be a straight function? (In either case, where's it belong?)

Pardon the apparent n00b-iness of the question. It's 'cause I'm honestly a n00b! This OOP stuff is giving my head a spin having been a procedural programmer for >30 years. (And I choose to learn it by jumping into an iPhone app. Talk about baptism by fire!)

Thanks in advance,
Bill

+1  A: 

The graph data and the code that processes it is part of your model, not your view or your controller. Create a separate class that encapsulates the graph and associated methods and pass an instance between the controllers that need to manipulate it.

Franci Penov
OK, well, that sounds simple enough.(Scratches head a bit...)(Scratches head some more...)(Will keep scratching until head loses all hair...)OK, let me see if I got this straight. I'm looking to create a class which I then programmatically add to the view. I can probably find sample code to that effect, though probably not as a new class. Can you outline that class for me, please? Also in that class, I add functions to describe the graph. (I think I can do that without too much help.)
BillEccles
Lol, you probably don't want to add the model class to the View. You probably want the model class to have a method that returns the data for the View to display the image. Your Controller should instantiate the model class and load the data from wherever you read the graph data.
Franci Penov
Btw, sorry for not giving a code sample - my Objective-C-fu is rather weak. My answer was based on the general approach to using the MVC pattern, which iPhone apps are rather fond of.
Franci Penov