Database Reference
In-Depth Information
As you can probably guess, this ties the number of rows in the table view to the
number of walks set in the currently selected dog.
Next, replace
tableView(_:cellForRowAtIndexPath:)
as follows:
func
tableView(tableView:
UITableView
,
cellForRowAtIndexPath
indexPath:
NSIndexPath
) ->
UITableViewCell
{
let
cell =
tableView.
dequeueReusableCellWithIdentifier
(
"Cell"
,
forIndexPath: indexPath)
as
UITableViewCell
let
dateFormatter =
NSDateFormatter
()
dateFormatter.
dateStyle
= .
ShortStyle
dateFormatter.
timeStyle
= .
MediumStyle
//the next two statements have changed
let
walk =
currentDog
.
walks
[indexPath.
row
]
as
Walk
cell.
textLabel
!.
text
=
dateFormatter.
stringFromDate
(walk.
date
)
return
cell
}
Only two lines of code have changed. Now, you take the date of each walk and
display it in the corresponding table view cell.
The
add
method still has a reference to the old
walks
array. Remove it for now—
you'll re-implement this method in the next step:
@IBAction
func
add(sender:
AnyObject
) {
//remove walks += NSDate()
tableView
.
reloadData
()
}
Build and run to make sure you've hooked up everything correctly: