Skip to content

Instantly share code, notes, and snippets.

@matteom
Last active December 28, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matteom/7549052 to your computer and use it in GitHub Desktop.
Save matteom/7549052 to your computer and use it in GitHub Desktop.
View controller to create new leads
// Header file
@protocol PCNewLeadViewControllerDelegate <NSObject>
- (void)newLeadWasCreated;
@end
@interface PCNewLeadViewController : UIViewController
@property NSManagedObjectContext *managedObjectContext;
@property (weak) id<PCNewLeadViewControllerDelegate> delegate;
@end
// Implementation file
@interface PCNewLeadViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *surnameTextField;
@property (weak, nonatomic) IBOutlet UITextField *companyTextField;
@end
@implementation PCNewLeadViewController
- (IBAction)save:(id)sender {
PCLead *newLead = [PCLead insertLeadInManagedObjectContext:self.managedObjectContext];
newLead.name = self.nameTextField.text;
newLead.surname = self.surnameTextField.text;
newLead.company = self.companyTextField.text;
[self.delegate newLeadWasCreated];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)cancel:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment