Database Reference
In-Depth Information
Now we need to add the IBAction that will be called when the user presses the add button:
#pragma mark - Button Methods
-(IBAction)btnAddPressed:(id)sender {
CloseFriend *closeFriend = [NSEntityDescription insertNewObjectForEntityForName:@"CloseFriend"
inManagedObjectContext:[AppDelegate managedObjectContext]];
_selectedFriend = closeFriend;
_shouldStartEditing = YES;
[self loadCloseFriends];
[self performSegueWithIdentifier:@"ToCloseFriendDetails" sender:nil];
}
This starts off with another Core Data method. We create our CloseFriend managed object by calling
a class method on NSEntityDescription with the signature insertNewObjectForEntityForName:
inManagedObjectContext: . We use our object name as the first parameter and pass our managed
object context as the second. Then we set our selectedFriend property and our shouldStartEditing
property. We set editing to YES in this case because we have a blank object. Finally we call our
loadCloseFriends method to reload our closeFriends array and then call our segue. Let's write our
prepareForSegue:sender: method now.
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"ToCloseFriendDetails"]){
[[segue destinationViewController] setDelegate:self];
[[segue destinationViewController] setCloseFriend:_selectedFriend];
[[segue destinationViewController] setShouldStartEditing:_shouldStartEditing];
}
}
Here we are just assigning our self as the delegate for the CloseFriendDetailViewController ,
sending our property _selectedFriend and sending our property _shouldStartEditing . Remember,
_shouldStartEditing is the Boolean value that determines if we launch the view in edit mode, or if
we are just viewing.
CloseFriendDetailViewController
Now we can lay the foundation for the CloseFriendDetailViewController . Select the CloseFriend
DetailViewController.h file and let's get to work. We start by adding an import statement for our
CloseFriend managed object just above the UIKit import.
#import "CloseFriend.h"
 
Search WWH ::




Custom Search