Tap on a cell to scroll up a keyboard.
Correct the spelling and then press the
return
key.
AppDelegate
:
unchanged.
TableViewController
Create the
TableViewController
as in
States.
When a cell is selected,
the
tableView(_:didDeselectRowAtIndexPath:)
method of the
table
view delegate
is called.
This method
adds a
UITextField
to the cell,
temporarily covering the cell’s
textLabel
.
The position, content, and color (fore and background) of the
UITextField
exactly match those of the
textLabel
.
When you press
return
,
the
UITextField
’s
text will be copied into the cell
and the
UITextField
will be destroyed.
Minor details.
A
UILabel
displays its text centered vertically.
A
UITextField
displays its text upper-left justified.
(Try to find this in the documentation!)
That’s why we needed the variable
dy
.
We change the
textLabel
’s
text to a blank just in case the background color is
clear.
Three methods of the
data
source
provide the data.
Our data source is the
UITableViewController
.
numberOfSectionsInTableView(_:)
tableView(_:numberOfRowsInSection:)
tableView(_:cellForRowAtIndexPath:)
UITableViewCell
.
UITableViewCell
that has a
UITextField
in place of the
UILabel
textLabel
?
Then every cell would contain a
UITextField
all the time.