Divide objects in your program into 3 camps.
= What your application is (but not how it is displayed)
= How your is presented to the user (UI logic)
= Your s minions
It s all about managing communication between camps
s can always talk directly to their.
outlet s can also talk directly to their.
outlet The and should never speak to each other.
outlet? Can the speak to its?
outlet Sort of. Communication is blind and structured.
target outlet The can drop a target on itself.
target outlet action Then hand out an action to the.
target outlet action The sends the action when things happen in the UI.
target outlet should will did action Sometimes the needs to synchronize with the.
should will did target outlet delegate action The sets itself as the s delegate.
should will did target outlet delegate action The delegate is set via a protocol (i.e. it s blind to class).
should will did target outlet delegate action s do not own the data they display.
should will did target outlet delegate action data at count So, if needed, they have a protocol to acquire it.
data at should will did count target outlet delegate data source action s are almost always that data source (not!).
data at should will did count target outlet delegate data source action s interpret/format information for the.
should target? data at will did count outlet data source delegate action Can the talk directly to the?
data at should will did count target outlet delegate data source action No. The is (should be) UI independent.
data at should will did count target outlet delegate data source action So what if the has information to update or something?
should target Notification & KVO data at will did count outlet data source delegate action It uses a radio station -like broadcast mechanism.
should target Notification & KVO data at will did count outlet data source delegate action s (or other ) tune in to interesting stuff.
should target Notification & KVO data at will did count outlet data source delegate action A might tune in, but probably not to a s station.
should target Notification & KVO data at will did count outlet data source delegate action Now combine MVC groups to make complicated programs...
MVCs working together
MVCs not working together
s working together What happens when your application gets more features? Now all of your UI can t fit in one MVC s view.
s working together What happens when your application gets more features? We never have an MVC s view span across screens. So we ll have to create a new MVC for these new features.
s working together So how do we switch the screen to show this other MVC?
s working together UINavigation We use a controller of controllers to do that. For example, a UINavigation.
s working together UINavigation The UINavigation is a whose looks like this.
MVCs working together UINavigation ro ot Vi ew Co nt ro ll er But it s special because we can set its root outlet to another MVC...
s working together UINavigation... and it will embed that MVC s inside its own.
s working together UINavigation Then a UI element in this (e.g. a UIButton) can segue to the other MVC and its will now appear in the UINavigation.
s working together UINavigation
s working together UINavigation Notice this Back button automatically appears.
s working together UINavigation When we click it, we ll go back to the first MVC.
s working together UINavigation
Calculator Calculator display CalculatorBrain digitpressed: CalculatorGraph graph? GraphDataSource
Calculator Calculator display CalculatorBrain digitpressed: CalculatorGraph graph? GraphDataSource
Calculator Calculator display CalculatorBrain digitpressed: CalculatorGraph graph? GraphDataSource
Calculator Calculator display CalculatorBrain digitpressed: CalculatorGraph graph? GraphDataSource
Calculator Calculator display CalculatorBrain digitpressed: CalculatorGraph CalculatorProgramsTable graph GraphDataSource Popover Segue UITableDataSource table? NSArray of programs
Calculator display Calculator When someone clicks in this table, we want to update the graph. How can we do that? CalculatorBrain digitpressed: CalculatorGraph CalculatorProgramsTable graph GraphDataSource Popover Segue UITableDataSource table? NSArray of programs
Calculator display Calculator We CANNOT directly ask this Graph to do it because we are (indirectly) part of that s. CalculatorBrain digitpressed: CalculatorGraph CalculatorProgramsTable graph GraphDataSource Popover Segue UITableDataSource table? NSArray of programs
Calculator Calculator display CalculatorBrain We do it in the normal way a can talk back to its : delegation. digitpressed: CalculatorGraph blec CalculatorProgramsTa Gr? ap gr hv ie wd at ap as hv ou ie rc e w CalculatorProgramsTable ontrollerdelegate gu e e S ver o p Po UI Ta bl ev ta ie wd at as bl ou ev rc ie w e NSArray of programs