A couple of weeks ago i have started my research in Iphone app development and after alot of hello world applications in different settings i am now ready for my very first application based on the MVC design pattern used in Cocoa.
This opens up alot of questions for me though and after reading the different class references about UIViews and controllers i am stuck in trying to figure out which one i should be using.
In my application i am trying to create a grid of small rectangle’s with each rectangle having a different text value on them, to be more specific, i am trying to create a simple calender that will display all the days of a month in a grid.
Every rectangle is a instance of a class i named Tile, in this class i want to implement the drawRect method to draw the rectangle for me and set the text value to the day it should represent.
In order to implement this i have done some research on how this should be done.
From what i have learned so far is that UIViewcontrollers do not really display anything, they are basically sitting there waiting to respond to any events from their children.
In my application i would translate this to the Controller that will respond to each touchevent on a tile.
A UIView however is also a container but one for objects that will need drawing methodes like drawRect. This would translate to the grid that will hold all of the tiles if i’m correct.
Except, i have no clue what subclass i should use for each tile, i have the feeling i am really missing some basic knowledge here but i just can’t figure it out.
Would really appreciate it if anyone could point me in the right direction with this.
If there were any two apple document you should read, it is the one about
UIViewControllers which can be found here and the one aboutUIViews which can be found here. TheUIViewController, as you mentioned, is more about integrating with the iOS system than being a visible component. It has a reference to aUIView, and thatUIViewis the root node in the visible tree of elements which starts at that View Controller.In iOS programming you don’t really need to worry about drawing rectangles, because for the most part you will be extending elements which know how to draw themselves and then just telling them where to go. The basic visible element in this case, is the
UIView. There are many different kinds ofUIViews (see the graphic in the UIView programming guide link), so for your case you could use a simpleUIViewwith a background image set to your calendar box graphic, and add a subview of typeUILabel.UILabelis a subclass ofUIView, so you know it will be something visible as well.Once you grasp these concepts (which can take a long time)
Interface Builderwill start to make more sense and you can start doing some of these things with it – and understand how its working. In essence it will create the hierarchy of aUIViewControllerreferencing a hierarchy ofUIViews automatically, then you.