Database Reference
In-Depth Information
Now we need to create our SettingsViewController class.
1.
Click File ➤ New ➤ File from the Xcode menu.
2.
Select create a new Objective-C Class and click Next. For Subclass of select
UITableViewController .
Type SettingsViewController for the Class and click Next.
3.
4. In the Finder window be sure that the file is being saved in your project folder
and be sure that iCloudTestApp is checked as the Target.
This class comes with a lot of boilerplate code that we don't need. Delete everything from the
line #pragma mark—Table view data source all the way down to just before @end . The reason we
don't need these methods is because we told the Storyboard that we were going to use Static
cells—therefore we don't need any of the data source or delegate methods.
In the SettingsViewController.m file we want to create two properties for the text fields that we
added. Add these two properties inside the private interface:
@property (weak, nonatomic) IBOutlet UITextField *txtDisplayName;
@property (weak, nonatomic) IBOutlet UITextField *txtFavoriteNumber;
We want these fields to already be filled in with the value we added to user defaults. We will create a
method called updateUI that will handle setting the text fields:
-(void)updateUI {
_txtDisplayName.text = [[NSUserDefaults standardUserDefaults] stringForKey:CTDisplayName];
_txtFavoriteNumber.text = [[NSUserDefaults standardUserDefaults] stringForKey:CTFavoriteNumber];
}
You should be getting used to getting these values from NSUserDefaults by now.
We will follow the exact same process as we did in the MainViewController for calling this updateUI
method. Add the viewWillAppear:animated method and call our updateUI method within it:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self updateUI];
}
Now that we have displaying our values out of the way, we need to implement some methods that
handle the inputting and changing of the values in the text fields. First we will write a method that
will save the text field value to our user defaults. We will branch from this method later and show
its importance. It would be less code to set these values, but because what we will implement with
KVS, we want minimize the saves to the KVS store.
 
Search WWH ::




Custom Search