Database Reference
In-Depth Information
Create View Controller Classes
Now that we have our Storyboard set up, it is time to write the code that will control it. Let's
start by creating a new Objective-C class that is a subclass of UITableViewController . Call it
CloseFriendsTableViewController .
We need to create another class for our UIViewController that will act as a detail view.
Add another Objective-C class that is a subclass of UIViewController and name it
CloseFriendDetailViewController .
CloseFriendsTableViewController
Open the CloseFriendsTableViewController.m file and add the import statement for our
CloseFriend managed object.
#import "CloseFriend.h"
Next, let's add some properties to the private interface. These should be self-explanatory.
@interface CloseFriendsTableViewController ()
@property (strong) NSArray *closeFriends;
@property (strong) CloseFriend *selectedFriend;
@property BOOL shouldStartEditing;
@end
Also, go ahead and delete the initWithStyle: method because we have no use for it. Inside the
viewDidLoad: method we need to add a method call to a method named loadCloseFriends . Add the
following line just after the [super viewDidLoad]; method call inside the viewDidLoad method.
[self loadCloseFriends];
Now add the loadCloseFriends method.
-(void)loadCloseFriends {
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"CloseFriend"
inManagedObjectContext:[AppDelegate managedObjectContext]];
[request setEntity:entity];
[request setSortDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"lastName"
ascending:YES]]];
NSError *error = nil;
NSArray *results = [[AppDelegate managedObjectContext] executeFetchRequest:request
error:&error];
if(error == nil){
_closeFriends = results;
} else {
NSLog(@"There was an error getting data - %@",error.localizedDescription);
}
}
 
Search WWH ::




Custom Search