Database Reference
In-Depth Information
In the MainViewController.m file remove the lines starting at #pragma mark — Flipside View all the
way down to right after the prepareForSegue:sender: method.
Now that we are done getting rid of the things we don't need, it is time to add the things that we do
need. Let's start by defining a property for the UILabel that we added to the view in the storyboard.
Inside the MainViewController private interface in the MainViewController.m file let's add the
following property:
@property (weak, nonatomic) IBOutlet UILabel *lblWelcome;
We define this object as weak because the storyboard handles the instantiation for us so we don't
need to create a strong reference to it. We will connect this outlet a little later.
Now we want to add a new method to handle updating the label with the properly formatted
welcome message. We call this method updateUI :
-(void)updateUI {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
_lblWelcome.text = [NSString stringWithFormat:@"Welcome %@\nYour favorite number is
%@",[userDefaults stringForKey:CTDisplayName],[userDefaults stringForKey:CTFavoriteNumber]];
}
As we have done previously, we start by getting a reference to the NSUserDefaults object. Then we
assign formatted text to our UILabel using our constants to access the proper NSUserDefault value.
Next we extend the viewWillAppear:animated method and call our updateUI method inside of it:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self updateUI];
}
The reason that we update the UI in the viewWillAppear: method, instead of the viewDidLoad:
method is because we know that we are going to be editing the user defaults inside the
SettingsViewController , previously known as the FlipsideViewController . This way every time the
view is displayed it updates the label and we see our changes take effect immediately.
Goodbye FlipsideViewController, Hello SettingsViewController
This is our final step in laying the base foundation for our app. We start of by deleting the
FlipsideViewController and creating a new class called SettingsViewController , which subclasses
UITableViewController . In this view controller we create some UITextField properties. We also
implement the UITextFieldDelegate protocol so we can interact with the text fields when certain
events happen. We also create a method that is called from the Bar Button Item when it is pressed.
Let's start by deleting the FlipsideViewController.h and FlipsideViewController.m files. When
prompted you can select Move to trash because we won't be needing these files anymore.
 
Search WWH ::




Custom Search