A
UITextView
is like the
UITextField
we saw
here,
except that a
UITextView
can hold many lines of text.
It can even scroll up and down because it is derived from class
UIScrollView
.
I gave the
UITextView
a view controller,
and a
tab bar controller
on top of that,
because everyone expects to see a navigation bar with a Done button.
main.m
SmokyAppDelegate
ViewController
also acts as the
UITextView
’s
delegate.
It contains the
right
bar button item,
“Done”.
The navigation bar is is 44 pixels (or pixel pairs) high in portrait orientation, 32 in landscape. The keyboard is 216 = 4 × 54 pixels high in portrait orientation, 162 = 3 × 54 in landscape.
The delegate of the
UITextView
is the
ViewController
.
See the
textViewShouldEndEditing:
textViewDidEndEditing:
ViewController
.
The
textViewDidEndEditing:
ViewController
writes the
text
of the
UITextView
into a file named
lyrics.txt
NSUTF8StringEncoding
because
NSASCIIStringEncoding
gave me the error message
“The file "lyrics.txt" could not be saved using
text encoding Western (ASCII).”
You can search for
lyrics.txt
Terminal.app
find / -name lyrics.txt 2> /dev/null /Users/nyuuser/Library/Application Support/iPhone Simulator/5.0/Applications/4179C056-DD8E-4F38-BCB7-38672121A658/lyrics.txt
We have to
cat
the file with
'
single quotes'
because the filename contains white space.
cat '/Users/nyuuser/Library/Application Support/iPhone Simulator/5.0/Applications/4179C056-DD8E-4F38-BCB7-38672121A658/lyrics.txt'
NSTemporaryDirectory
instead of
NSHomeDirectory
.