7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 1/66
Developing Applications for iOSFall 2011
Stanford CS193p
Text
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 2/66
TodayTable ViewDisplaying a dynamic list of data.
Or displaying a fixed table of data.
DemoFavorite graphs feature in Calculator.Popover with delegate call back.Table view with dynamic list of data.
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 3/66
UITableViewVery important class for displaying data in a tableOne-dimensional table.
It’s a subclass of UIScrollView.Table can be static or dynamic (i.e. a list of items).
Lots and lots of customization via a dataSource protocol and a delegate protocolVery efficient even with very large sets of data.
Displaying multi-dimensional tables ...Usually done via a UINavigationController containing multiple MVC’s where View
Kinds of UITableViewsPlain or Grouped
Static or DynamicDivided into sections or notDifferent formats for each row in the table (including completely customized)
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 4/66
UITableViewUITableViewStylePlain UITableViewStyleGrouped
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 5/66
UITableView
Table Cell
Table Footer
Table HeaderSection Hea
Section Foote
Section
Plain Style
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 6/66
UITableView
Table Cell
Table Footer
Table Header
Section Hea
Section Foote
Section
Grouped Style
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 7/66
Sections or Not
SectionsNo Sections
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 8/66
Cell Type
BasicSubtitle Right Detail LUITableViewCellStyleSubtitle UITableViewCellStyleDefault UITableViewCellStyleValue1 UITa
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 9/66
UITableViewController iOS class used as the base class for MVC’s that display UITableViews
Just drag one out in Xcode, create a subclass of it and you’re on your way!
Creating Table View MVCs
DraggingUITableViewC
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 10/66
UITableViewController iOS class used as the base class for MVC’s that display UITableViews
Just drag one out in Xcode, create a subclass of it and you’re on your way!
Creating Table View MVCs
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 11/66
UITableViewController iOS class used as the base class for MVC’s that display UITableViews
Just drag one out in Xcode, create a subclass of it and you’re on your way!
Creating Table View MVCs
Choose New File menu to
subUITableVi
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 12/66
UITableViewController iOS class used as the base class for MVC’s that display UITableViews
Just drag one out in Xcode, create a subclass of it and you’re on your way!
Creating Table View MVCs
Choose New File menu to
subUITableVi
Be sure tsuperc
UITableView
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 13/66
UITableViewController iOS class used as the base class for MVC’s that display UITableViews
Just drag one out in Xcode, create a subclass of it and you’re on your way!
Creating Table View MVCs
And to setstoryboa
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 14/66
UITableView You can customize both the look of the table view and its cells from Xcode.
Click on the table view (not the table view controller) to see its properties in the
Creating Table View MVCs
Click here UITableVi
UITableViewC
Then you shoview propeAttribute
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 15/66
UITableView You can customize both the look of the table view and its cells from Xcode.
Click on the table view (not the table view controller) to see its properties in the
Creating Table View MVCs
We’ll taprototypeTable Viebut for no
Static
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 16/66
UITableView You can customize both the look of the table view and its cells from Xcode.
Click on the table view (not the table view controller) to see its properties in the
Creating Table View MVCs
This table viewLet’s chang
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 17/66
UITableView You can customize both the look of the table view and its cells from Xcode.
Click on the table view (not the table view controller) to see its properties in the
Creating Table View MVCs
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 18/66
UITableViewCell And you can change the look of each cell as well.
Click on a cell that you want to change and set its attributes in the Inspector.
Creating Table View MVCs
Click to seleproperties
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 19/66
UITableViewCell And you can change the look of each cell as well.
Click on a cell that you want to change and set its attributes in the Inspector.
Creating Table View MVCs
Change Style
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 20/66
UITableViewCell And you can change the look of each cell as well.
Click on a cell that you want to change and set its attributes in the Inspector.
Creating Table View MVCs
Change Style
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 21/66
UITableViewCell And you can change the look of each cell as well.
Click on a cell that you want to change and set its attributes in the Inspector.
Creating Table View MVCs
Change Style
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 22/66
UITableViewCell And you can change the look of each cell as well.
Click on a cell that you want to change and set its attributes in the Inspector.
Creating Table View MVCs
Change Sty
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 23/66
UITableViewCell And you can change the look of each cell as well.
Click on a cell that you want to change and set its attributes in the Inspector.
Creating Table View MVCs
Double-click t
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 24/66
UITableViewCell And you can change the look of each cell as well.
Click on a cell that you want to change and set its attributes in the Inspector.
Creating Table View MVCs
Show discloThis should clicking on a
brings upDisclosure Accessory
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 25/66
UITableViewCell And you can change the look of each cell as well.
Click on a cell that you want to change and set its attributes in the Inspector.
Creating Table View MVCs
Show checThis can
multiple sel
(requires soCheckmark Accessory
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 26/66
UITableViewCell And you can change the look of each cell as well.
Click on a cell that you want to change and set its attributes in the Inspector.
Creating Table View MVCs
Show detail dThis is an
Use it to shClicking on the
the “main thDetail Disclosure Accessory
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 27/66
UITableViewCell
Creating Table View MVCs
User taps on the blue detail disclosure below? This will be sent to your UITableV
- (void)tableView:(UITableView *)tv accessoryTappedForRowAtIndexPath:(N
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 28/66
UITableViewCell
Creating Table View MVCs
Notice that some cell styles can have an image.
You can set this in the code as well (more in a moment on this).
ti bl i
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 29/66
UITableViewCell
Creating Table View MVCs
Notice that some cell styles can have an image.
You can set this in the code as well (more in a moment on this).
C ti T bl Vi MVC
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 30/66
UITableViewCell
Creating Table View MVCs
In the Custom style, you can drag out views and wire them up as outlets!
Dragging a but
C ti T bl Vi MVC
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 31/66
UITableViewCell
Creating Table View MVCs
In the Custom style, you can drag out views and wire them up as outlets!
C ti T bl Vi MVC
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 32/66
UITableViewCell
Creating Table View MVCs
In the Custom style, you can drag out views and wire them up as outlets!
C ti T bl Vi MVC
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 33/66
UITableViewCell
Creating Table View MVCs
In the Custom style, you can drag out views and wire them up as outlets!
C ti T bl Vi MVC
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 34/66
UITableViewCell All of the above examples were “static” cells (setup in the storyboard). Not a dyn
If you switch to dynamic mode, then the cell you edit is a “prototype” for all cells¬
Creating Table View MVCs
Switch to a with Prot
C ti T bl Vi MVCs
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 35/66
UITableViewCell All of the above examples were “static” cells (setup in the storyboard). Not a dyn
If you switch to dynamic mode, then the cell you edit is a “prototype” for all cells¬
Creating Table View MVCs
Now click onedit it. All will be like
(though we’lto be diff
Creatin Table View MVCs
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 36/66
UITableViewCell All of the above examples were “static” cells (setup in the storyboard). Not a dyn
If you switch to dynamic mode, then the cell you edit is a “prototype” for all cells¬
Creating Table View MVCs
Now click onedit it. All will be like
(though we’lto be diff
You shouldpropert
Attrib
Creating Table View MVCs
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 37/66
UITableViewCell All of the above examples were “static” cells (setup in the storyboard). Not a dyn
If you switch to dynamic mode, then the cell you edit is a “prototype” for all cells¬
Creating Table View MVCs
Let’s changstyle to be S
Creating Table View MVCs
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 38/66
UITableViewCell All of the above examples were “static” cells (setup in the storyboard). Not a dyn
If you switch to dynamic mode, then the cell you edit is a “prototype” for all cells¬
Creating Table View MVCs
This is a veryIt is the nareference identify t
(more on th
Creating Table View MVCs
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 39/66
UITableViewCell All of the above examples were “static” cells (setup in the storyboard). Not a dynIf you switch to dynamic mode, then the cell you edit is a “prototype” for all cells¬
Creating Table View MVCs
Pick a name “My Table probably n
Something like(if this wer
would
UITableView Protocols
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 40/66
UITableView ProtocolsHow do we connect to all this stuff in our code?A UITableView has two important @propertys: its delegate and its dataSource.
The delegate is used to control how the table is displayed. The dataSource provides the data what is displayed inside the cells.
Your UITableViewController is automatically set as the UITableView’s delegate
Your UITableViewController subclass will also have a property that points to th@property (nonatomic, strong) UITableView *tableView;
To be “dynamic,” we need to be the UITableView’s dataThree important methods in this protocol:How many sections in the table?How many rows in each section?Give me a UIView to use to draw each cell at a given row in a given section.
Let’s cover the last one first ...
UITableViewDataSource
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 41/66
UITableViewDataSourceHow do we control what is drawn in each cell in a dynaEach row is drawn by its own instance of UITableViewCell (a UIView subclass).Here is the UITableViewDataSource method to get that cell for a given row in a
- (UITableViewCell *)tableView:(UITableView *)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}
In a table, you do not need to implement this method(though you can if you want to ignore what’s in the storyboard).
UITableViewDataSource
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 42/66
UITableViewDataSourceHow do we control what is drawn in each cell in a dynaEach row is drawn by its own instance of UITableViewCell (a UIView subclass).Here is the UITableViewDataSource method to get that cell for a given row in a
- (UITableViewCell *)tableView:(UITableView *)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}
NSIndexPath is just an object wiproperties for use with UITableVie
UITableViewDataSource
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 43/66
UITableViewDataSourceHow do we control what is drawn in each cell in a dynaEach row is drawn by its own instance of UITableViewCell (a UIView subclass).Here is the UITableViewDataSource method to get that cell for a given row in a
- (UITableViewCell *)tableView:(UITableView *)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// get a cell to use (instance of UITableViewCell)
// set @propertys on the cell to prepare it to display
}
UITableViewDataSource
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 44/66
UITableViewDataSourceHow do we control what is drawn in each cell in a dynaEach row is drawn by its own instance of UITableViewCell (a UIView subclass).Here is the UITableViewDataSource method to get that cell for a given row in a
- (UITableViewCell *)tableView:(UITableView *)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// get a cell to use (instance of UITableViewCell)
// set @propertys on the cell to prepare it to display}
UITableViewCell *cell; cell = [self.tableView dequeueReusableCellWithIdentifier:@“My Table
This MUST match what is in your storyboaryou want to use the prototype you defined t
UITableViewDataSource
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 45/66
UITableViewDataSourceHow do we control what is drawn in each cell in a dynaEach row is drawn by its own instance of UITableViewCell (a UIView subclass).Here is the UITableViewDataSource method to get that cell for a given row in a
- (UITableViewCell *)tableView:(UITableView *)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// get a cell to use (instance of UITableViewCell)
// set @propertys on the cell to prepare it to display}
UITableViewCell *cell; cell = [self.tableView dequeueReusableCellWithIdentifier:@“My Table
The cells in the table actually reused.When one goes off-screen, it gets put into a “reuse pool.”
The next time a cell is needed, one is grabbed from the reuse pool if availablIf none is available, one will be put into the reuse pool if there’s a prototype in the st
Otherwise this dequeue method will return nil (let’s deal with that ...).
UITableViewDataSource
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 46/66
UITableViewDataSourceHow do we control what is drawn in each cell in a dynaEach row is drawn by its own instance of UITableViewCell (a UIView subclass).Here is the UITableViewDataSource method to get that cell for a given row in a
- (UITableViewCell *)tableView:(UITableView *)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// get a cell to use (instance of UITableViewCell)
// set @propertys on the cell to prepare it to display}
UITableViewCell *cell; cell = [self.tableView dequeueReusableCellWithIdentifier:@“My Table
if (!cell) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellSt
reuseIdentifier:@“My Table View C}
UITableViewDataSource
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 47/66
UITableViewDataSourceHow do we control what is drawn in each cell in a dynaEach row is drawn by its own instance of UITableViewCell (a UIView subclass).Here is the UITableViewDataSource method to get that cell for a given row in a
- (UITableViewCell *)tableView:(UITableView *)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// get a cell to use (instance of UITableViewCell)
}
UITableViewCell *cell; cell = [self.tableView dequeueReusableCellWithIdentifier:@“My Table
if (!cell) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellSt
reuseIdentifier:@“My Table View C}cell.textLabel.text = [self getMyDataForRow:indexPath.row inSection
return cell;
There are obvioucan do in the cell b
(detail text, imag
UITableViewDataSource
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 48/66
UITableViewDataSourceHow does a dynamic table know how many rows thereAnd how many sections, too, of course?- (NSInteger)numberOfSectionsInTableView:(UITableView *)sender; - (NSInteger)tableView:(UITableView *)sender numberOfRowsInSection:(NSInte
Number of sections is 1 by defaultIn other words, if you don’t implement numberOfSectionsInTableView:, it will be
No default for number of rows in a sectionThis is a required method in this protocol (as is tableView:cellForRowAtIndexPath
What about a static table?Do not implement these dataSource methods for a static table.UITableViewController will take care of that for you.
UITableViewDataSource
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 49/66
UITableViewDataSourceThere are a number of other methods in this protocolBut we’re not going to cover them today.They are mostly about getting the headers and footers for sections.
And about dealing with editing the table (moving/deleting/inserting rows).
UITableViewDelegate
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 50/66
UITableViewDelegateAll of the above was the UITableView’s dataSourceBut UITableView has another protocol-driven delegate called its delegate.
The delegate controls how the UITableView is displayeNot what it displays (that’s the dataSource’s job).
Common for dataSource and delegate to be the same Usually the Controller of the MVC in which the UITableView is part of the (or is
The delegate also lets you observe what the table vieEspecially responding to when the user selects a row.We often will use segues when this happens, but we can also track it directly.
Table View “Target/Action”
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 51/66
Table View Target/ActionUITableViewDelegate method sent when row is selecteThis is sort of like “table view target/action”You might use this to update a detail view in a split view if master is a table view
- (void)tableView:(UITableView *)sender didSelectRowAtIndexPath:(NSInde
{ // go do something based on information
// about my data structure corresponding to indexPath.row in indexPath.s}
Lots and lots of other delegate methods
will/did methods for both selecting and deselecting rowsProviding UIView objects to draw section headers and footersHandling editing rows (moving them around with touch gestures)willBegin/didEnd notifications for editing.Copying/pasting rows.
Table View Segues
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 52/66
Table View SeguesYou can segue when a row is touched, just like from aSegues will call prepareForSegue:sender: with the chosen UITableViewCell asYou can tailor whatever data the MVC needs to whichever cell was selected.
Table View Segues
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 53/66
Table View SeguesYou can segue when a row is touched, just like from aSegues will call prepareForSegue:sender: with the chosen UITableViewCell asYou can tailor whatever data the MVC needs to whichever cell was selected.
Table View Segue
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 54/66
Ta le Vie Seg eThis works whether dynamic or static- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender]; // prepare segue.destinationController to display based on information
// about my data structure corresponding to indexPath.row in indexPath.s}
UITableView
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 55/66
What if your Model changes?- (void)reloadData; Causes the table view to call numberOfSectionsInTableView: and numberOfRows
all over again and then cellForRowAtIndexPath: on each visible cell.Relatively heavyweight obviously, but if your entire data structure changes, that’sIf only part of your Model changes, there are lighter-weight reloaders, for exam
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animationStyle
There are dozens of other methods in UITableView
Setting headers and footers for the entire tableControlling the look (separator style and color, default row height, etc.)Getting cell information (cell for index path, index path for cell, visible cells, etc.)Scrolling to a rowSelection management (allows multiple selection, getting the selected row, etc.)
Moving, inserting and deleting rows, etc.
Demo
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 56/66
Favorite GraphsAdd a feature to homework 3.Put an “Add to Favorites” button in graph view.
Add a “Favorites” bar button which brings up a list of the favorite graphs.
Watch for ...Deciding and advertising that an id parameter in a public API is a “property list”
(we just say it is so and then be sure not to break our promise to users of our
Storing a property list in NSUserDefaults.Building a table-view-based view controller subclass.
Implementing the UITableView dataSource protocol to show a dynamic list of datUsing a delegate to report the results of a popover to the object which puts theCalling popViewControllerAnimated: (and/or dismissPopoverAnimated:) from de
CalculatorCalculatorViewController
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 57/66
CalculatorBrain
?
digitPressed:
display
G r a p h V i e w D a t a S o u r c e
g r a p h V i e w
CalculatorGraphViewController
CalculatorCalculatorViewController
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 58/66
CalculatorBrain
?
digitPressed:
display
G r a p h V i e w D a t a S o u r c e
g r a p h V i e w
CalculatorGraphViewController
CalculatorCalculatorViewController
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 59/66
CalculatorBrain
?
digitPressed:
display
G r a p h V i e w D a t a S o u r c e
g r a p h V i e w
CalculatorGraphViewController
CalculatorCalculatorViewController
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 60/66
CalculatorBrain
?
digitPressed:
display
G r a p h V i e w D a t a S o u r c e
g r a p h V i e w
CalculatorGraphViewController
CalculatorCalculatorViewController
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 61/66
CalculatorBrain
?
digitPressed:
display
G r a p h V i e w D a t a S o u r c e
g r a p h V i e w
CalculatorGraphViewController
NSArray of programs
U I T a
CalculatorProgramsT
P o p o v e
r S e g u e
CalculatorCalculatorViewController
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 62/66
CalculatorBrain
?
digitPressed:
display
G r a p h V i e w D a t a S o u r c e
g r a p h V i e w
CalculatorGraphViewController
NSArray of programs
U I T a
CalculatorProgramsT
P o p o v e
r S e g u e
When someonwe want to
How ca
CalculatorCalculatorViewController
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 63/66
CalculatorBrain
?
digitPressed:
display
G r a p h V i e w D a t a S o u r
c e
g r a p h V i e w
CalculatorGraphViewController
NSArray of programs
U I T a
CalculatorProgramsT
P o p o v e
r S e g u e
We CANNOT directlController to do it becau
part of that Con
CalculatorCalculatorViewController
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 64/66
CalculatorBrain
?
digitPressed:
display
G r a p h V i e w D a t a S o u r
c e
g r a p h V i e w
CalculatorGraphViewController
NSArray of programs
U I T a
CalculatorProgramsT
P o p o v e
r S e g u e
CalculatorPrograms Table Vie wController
Delegate
We do it in thea View can talk
Controller: d
Steps to Delegate
7/29/2019 Lecture 9 Slides October 25 2011
http://slidepdf.com/reader/full/lecture-9-slides-october-25-2011 65/66
5 Steps1. Create the @protocol
2. Add delegate @property to delegator’s public @interface
3. Use delegate property inside delegator’s implementation4. Set the delegate property somewhere inside the delegate’s @implementation
5. Implement the protocol’s method(s) in the delegate (include <> on @interface)
Coming Up