Database Reference
In-Depth Information
19.
Change the width of the cell to 132 .
20.
Select the text field and change the width to 150 and the x to 155 .
It Is Time for Some Code!
We can now write some code. We start off by removing the FlipSideViewController files because
we no longer need them. Next, we create a constants file that store constants that we use when
dealing with user defaults. Then we make some edits to the CTAppDelegate files so that we can set
up our user defaults and save them. Moving on, we will edit the MainViewController file to handle
the label that displays our welcome text. And finally we create a new UITableViewController to call
SettingsViewController . It handles the text input on the Settings screen and also handles calling
the methods that we created in the Application Delegate to handle saving our user defaults.
Constants File
The use of a constants file is common in object-oriented programming. This process allows us to set
up either class-based static values or global static values for use in our code. In this case, we go the
global route because our project is a simple app.
1.
Select File ➤ New ➤ File. . . from the Xcode menu.
2.
Under iOS, select Cocoa Touch.
3.
From the screen on the right select Objective-C Class and click Next.
4.
Name this class Constants.
5.
Set Subclass of to NSObject if not already set and click Next.
6.
In the Finder window, be sure that the class is going to be saved inside your
project.
7. Under Targets, be sure that iCloudTestApp is checked and click Create.
We can go ahead and delete the interface and the implementation in the corresponding Constants.h
and Constants.m files because we won't need those.
Now define two constants: CTDisplayName and CTFavoriteNumber . In Constants.h add the following
two lines:
NSString * const CTDisplayNameKey;
NSString * const CTFavoriteNumberKey;
In the Constants.m file give these variables values by adding the following:
NSString * const CTDisplayNameKey = @"DISPLAY_NAME";
NSString * const CTFavoriteNumberKey = @"FAVORITE_NUMBER";
 
Search WWH ::




Custom Search