RSS

Core Data Basics Part 1 – Storyboards, Delegation

09 Feb


Introduction

Welcome to my tutorial set ‘Core Data Basics’. The aim of this set is to get you up and running with Core Data attached views as fast as possible.  If you’re new to objective-c programming you may wish to run through the iOS Newbie series first.  I’m going to provide raw essentials only so you don’t get too overwhelmed. I’m writing this tutorial set as a personal learning exercise because I found Core Data difficult to learn. I hope my ‘everything-you-need-and-nothing-you-don’t’ tutorial technique brings you up to speed quickly.

Prerequisites

To follow this tutorial I assume you know how to use Xcode at least in a basic sense. Again, try the iOS Newbie series if you’re lost.

Create a new iOS ‘Single View Application’:

Call the project ‘Staff Manager’ and ensure the Device Family is iPhone:

Link to the Core Data Framework (click the + sign shown below to add it):

Creating a Storyboard

A Storyboard is a canvas where you can design your view based app. To view the storyboard simply select MainStoryboard.storyboard and you will see the default View. You can navigate between items in the View Controller Scene in a hierarchy on the left, which is useful when scenes become complicated.

Lets get started.  First delete the default view and the view controller so there is nothing in the scene. Now we can really start creating the app from scratch.

Drag a Table View Controller onto the canvas (via Utilities, Objects):

Select the Table View so it has a blue outline then click Editor > Embed In > Navigation Controller. Next rename the Table View Controller to Roles (via Attributes Inspector, Navigation Item, Title):

Select the Prototype Cell of the Table View Controller then set the Identifier of the Prototype Cell to Roles Cell (via Attributes Inspector, Table View Cell):

Drag a Bar Button Item onto the top right bar of the Table View Controller (via Utilities, Objects) then change the Bar Button Item identifier to ‘Add’ (via Attributes Inspector, Bar Button Item):

Drag a new Table View Controller onto the canvas (via Utilities, Objects) then re-align it so it is to the right of the Roles Table View Controller:

Create a Push Segue (Seg-way) from the Add button to the new Table View Controller by holding down the Control key and dragging from the Roles ’Add’ button to the Add Roles Table View Controller:

Notice that the new Table View Controller is automatically embedded in a Navigation Controller. Rename the new Table View Controller to Add Role the same way we did for the Roles Table View Controller (via Attributes Inspector, Navigation Item, Title).  Run the app in the simulator to see what you have created so far with zero code!

Nice huh!  Now it’s time to further customise the Add Role view so it is ready for data entry.

Select the Add Role Table View then change the Content Type to Static Cells. Also change the Table View Style to Grouped then delete two of the Table View Cells.  Select the Table View Section then set the Header Name to Role Name.  After all that the Add Role Table View Controller should look like this:

If we ever want to enter data we need a Text Field so drag one on to the Add Role Table View Cell (via Utilities, Objects)

Change Text Field Border Style to invisible and resize it so that it fits nicely in the Table View Cell.  I find 260w 43h is a nice fit.  Set the Font to System 17 and Min Font Size to 17.

Finally, drag a Bar Button Item to the top right of the Add Role view and change it’s identifier to Save (via Attributes Inspector, Bar Button Item).

Run the app again and it should look like this when you tap the +

View Delegation

When you are in the Add Role view  you can already get back to Roles by pressing the automatically generated ‘Roles‘ button (top left).  If we want to go back to Roles when we click Save we need to configure the Roles view as a delegate of Add Roles view.

To do any customisation on a Table View Controller we need to subclass it. To make one click File > New > New File then create a New UIViewController subclass:

Ensure you select UITableViewController and call it RolesTVC:

Create another Table View Controller called AddRoleTVC in the same way so you now have two new UITableViewController subclasses:

Head back to MainStoryboard.storyboard again then select the Roles Table View Controller so it has a blue outline. Change the Class to RolesTVC (via Identity Inspector, Custom Class). Use the same technique for the Add Roles Table View Controller to set its custom class to AddRoleTVC:

Now that each Table View Controller has its own sub class we can start customising them. Our first order of business will be to edit AddRoleTVC to allow delegation by declaring a protocol AddRoleTVCDelegate. Change all the code in AddRoleTVC.h as follows:

#import 
 
@class AddRoleTVC;
@protocol AddRoleTVCDelegate
- (void)theSaveButtonOnTheAddRoleTVCWasTapped:(AddRoleTVC *)controller;
@end
 
@interface AddRoleTVC : UITableViewController
@property (nonatomic, weak) id <AddRoleTVCDelegate> delegate;
 
- (IBAction)save:(id)sender;
 
@end

Next change all the code in AddRoleTVC.m as follows:

#import "AddRoleTVC.h"
 
@implementation AddRoleTVC
@synthesize delegate;
 
- (void)viewDidUnload
{
    [super viewDidUnload];
}
- (IBAction)save:(id)sender
{
    NSLog(@"Telling the AddRoleTVC Delegate that Save was tapped on the AddRoleTVC");
    [self.delegate theSaveButtonOnTheAddRoleTVCWasTapped:self];
}
@end

Great! Now we can configure RolesTVC as a delegate of the AddRoleTVC.  To do that simply change all the code in RolesTVC.h as follows:

#import
#import "AddRoleTVC.h" // so this class can be a AddRoleTVCDelegate
 
@interface RolesTVC : UITableViewController <AddRoleTVCDelegate>
@end

Also change all the code in RolesTVC.m as follows:

#import "RolesTVC.h"
 
@implementation RolesTVC
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Roles Cell";
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
 
    // Configure the cell...
 
    return cell;
}
 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
	if ([segue.identifier isEqualToString:@"Add Role Segue"])
	{
        NSLog(@"Setting RolesTVC as a delegate of AddRolesTVC");
 
        AddRoleTVC *addRoleTVC = segue.destinationViewController;
        addRoleTVC.delegate = self;
	}
}
 
- (void)theSaveButtonOnTheAddRoleTVCWasTapped:(AddRoleTVC *)controller
{
    // do something here like refreshing the table or whatever
 
    // close the delegated view
    [controller.navigationController popViewControllerAnimated:YES];
}
 
@end

The delegation that we have just set up won’t work until we have set the identifier of the Segue on the storyboard. Set the name of the Segue to Add Role Segue (via Attributes Inspector, Storyboard Segue):

If you look in the prepareForSegue method found in RoleTVC.m you will notice that the AddRoleTVC delegation is set up in there. What that means is that any time the Add Role Segue is used that a delegate ‘anchor’ is created by prepareForSegue so we know how to get back to the Roles view once we’re finished with the AddRole view.  I hope that makes sense, it was a difficult concept for me to grasp originally however is very important for you to understand.

Lastly link the Save button to the save action by holding down control and dragging a line from the Save button down to the yellow circle on the Add Role Table View Controller.  You should get a pop-up on which you should select ‘save’:

Run the app in the simulator, tap the + sign then tap Save.  Look in the log window of Xcode for the following entries.  You can should now see delegation occurring:

While it might seem all very boring now the ground work has been set to start working with Core Data.

Stay tuned for Part 2 which should get a whole lot more interesting!!

Here’s the source code so far

If you liked this tutorial or found something wrong with it please let me know!

If you want to support my work and have an iPad please consider purchasing iSoccer *wink*

-Tim

Go to Part 2 or visit Tutorials Index


Be Sociable, Share!
 

About Tim Roadley

I'm a 30 something year old married-with-children Infrastructure Manager living in Australia and working at Cuscal. I love iOS coding and have found the most effective way to learn (and retain) is by writing tutorials. I love getting feedback and helping like minded people learn iOS too :)
69 Comments

Posted by on February 9, 2012 in iOS Tutorials

 

69 Responses to Core Data Basics Part 1 – Storyboards, Delegation

  1. adrian phillips

    February 10, 2012 at 1:11 am

    once again a great job tim. i tried to create the delegate the way you did with the 2 tableviewcontrollers. but it seems that is not working for me. when declaring the add rolesdelegate takes place in addroleTVC header file, in implementation you have roleTVC instead of addroletvc that brings up a big time error and also delegate that gets called is showing as undeclared which brings ap a couple of more errors.

    i truly like the way you deal with the surges and was wondering if the source code can be provided so i can take a look at it and find out where i went wrong. i can clearly see from the screen shot of the log that this is a workable set of codes but i am having trouble building it.

    once again thanks for taking the time to share this with us.

    adrian

     
    • Tim Roadley

      February 10, 2012 at 6:08 am

      I see what I have done, was wrestling with wordpress add-ons that were ‘tidying up’ my code!

      Please try again by copying and pasting the code out again into your project.

       
      • adrian phillips

        February 10, 2012 at 6:59 am

        got the source code and it works just fine. i had one warning which was related to the spacing before i downloaded the source code. it works very neat. the log messages are also helpful. i also added the fetch data class to the project in anticipation of the second and third part of the tutorial.

        very cool man. it is a very helpful work since iOS 5 and story boarding is a new idea. i am working on a drill down table view app with arc and storyboarding just to learn and i think your set of tutorial is going to be a great help not just in handling core data, but to understand storyboarding and arc.

        great job again tim.

        adrian

         
      • Tim Roadley

        February 10, 2012 at 7:29 am

        Ah cool. I realised I included the classed from next part of the tutorial with the source code from this one. I have re-uploaded the part 1 source without CoreDataTableViewController class. This way the tutorials will flow together properly ;-)

         
  2. Bill Spivey

    March 5, 2012 at 1:23 pm

    Thanks for the tutorial Tim. I was able to follow all the steps, with almost no trouble. I’ll proceed through the other tuts as I’m very interested in learning about Core Data, but finding that most of the material is either out-of-date, or just too obtuse to follow. Yours is different.

     
    • Tim Roadley

      March 5, 2012 at 1:36 pm

      Bill,

      I’m glad you’re finding these tutorials useful. If you get stuck on something along the way just let me know and I’ll try to clear things up!

      Cheers

      Tim

       
  3. Ram

    March 17, 2012 at 12:39 am

    Nice one good tutorial.

     
  4. Colm Brazel

    March 20, 2012 at 5:44 am

    Everything worked except for last step, hooking up save button to sent action ‘save’ on the add role table view, the sent action doesn’t appear so it can’t be linked to, but it works fine and is visible in the downloaded code, so still looking at this. Thanks again, Colm.

     
    • Dan Brown

      May 25, 2012 at 3:50 pm

      I’m having the exact issue as you. My available “Storyboard Segues” are Push, Modal and Custom. I am very new to Xcode, so any information would be much appreciated. Thanks, Dan.

       
      • Mick

        September 17, 2012 at 12:41 pm

        This Tutorial is fantastic!! However I’m having the same issue linking the save button. The save option isn’t available, just “Push, Modal, Custom. If I look in the First responder there’s a Save, but I dare not go down that road.

         
      • Mick

        September 17, 2012 at 1:00 pm

        I figured it out. I went back through and noticed that in the storyboard Add Role I had not set the custom class to AddRoleTVC. Once I made that change, the Save Connection was available.
        This is maybe the best Tutorial on Core Data in all internetdom. Thanks Soooo Much.

         
  5. DuRand Jones

    March 21, 2012 at 10:25 am

    Thanks for the tutorial Tim, I found it very helpful.

     
  6. Mike

    March 23, 2012 at 11:13 am

    Great Tutorial!

    im going to go buy isoccer.

    your a blessing

     
  7. Christina

    March 25, 2012 at 9:15 am

    Is it possible to have a table view populated by NSArray with a set list that then goes onto include core data? For example set categories —> list of editable items? Thanks

    You make it sound so easy :o)

     
  8. Terry

    March 28, 2012 at 8:45 am

    Hi Tim – great tutorial; very easy to follow and thorough. One comment – in using iOS 5.1 (don’t know about the earlier versions) when creating a tableviewController.h and .m, it generates the protocol skeleton code in the .m file for handling datasource and tableview selections, so when you say to replace all of the code with your provided code, perhaps you don’t want to have all of this skeleton code replaced?

     
  9. saravanan

    March 30, 2012 at 3:08 am

    Great job! thanks

     
  10. Pallavi

    April 2, 2012 at 9:45 pm

    Thank you so much Tim, for this tutorial. The iOS Core Data Tutorial is not updated for use with storyboards and I too found the concepts in Core Data a bit difficult to understand. Your tutorial has helped me to get through it quick and easy. Thanks again.

     
  11. LAOMUSIC ARTS

    April 4, 2012 at 5:59 pm

    Well done mate !
    Finally a clear explanation on Core Data !
    Thank you very much !

    P.S.: When one teach, two learn.

     
  12. Chuck

    April 7, 2012 at 5:00 am

    Tim:

    Thanks for your demos. Objective C newbie here.

    I am trying to write an app that does not depend on table view controllers, but does utilize Core Data. How would you incorporate Core Data and database functionality outside of a table view?

    Any info you could point me to would be great. So much of the demos interlink core data with table views that it is difficult to follow what is the database functionality and what is the table view controller functionality.

    Thanks in advance for any help on this.

    Chuck

     
    • Tim Roadley

      April 7, 2012 at 9:53 am

      Hi Chuck,

      I’ll probably write a tutorial on that in the future. For now I would examine the code in the CoreDataTableViewController and just adapt that to populate an NSMutableArray by passing [self.fetchedResultsController fetchedObjects] into the array. Once you have that array you’re good to go!

      Hope that hint helps in the mean time.

      Cheers

       
      • Chuck

        April 10, 2012 at 7:01 am

        Thanks for the reply. I’ll try it out.

         
  13. Gaz

    April 8, 2012 at 5:01 am

    Great tutorial mate! Thanks a lot!

     
  14. LAOMUSIC ARTS

    April 10, 2012 at 6:45 pm

    AddRoleTVC.h should ready ?

    #import

    (I was missing a name for the import)

     
  15. code Mike

    May 12, 2012 at 1:14 am

    Hey Tim, you are really great at presenting tutorials. I came across this tutorial today and so far, while working with part one of the tutorial i get the following exception below, if you don’t mind, please help me out. I will be glad if i got a reply from you. I am new to iPhone programming though i really bad when it comes to debugging.

    Please, post more tutorials to help become a good ios developer, i will reading and posting this your blog everyday.

    Thank you very much and keep up the work.


    2012-05-12 00:05:40.590 StaffManager[4446:fb03] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key save.'
    *** First throw call stack:
    (0x12b9022 0x176acd6 0x12b8ee1 0xca0022 0xc11f6b 0xc11edb 0xc2cd50 0x51471a 0x12badea 0x12247f1 0x51326e 0x71ceef 0x71d477 0x12bae99 0x2f514e 0x533a0e 0x12bae99 0x2f514e 0x2f50e6 0x39bade 0x39bfa7 0x39b266 0x31a3c0 0x31a5e6 0x300dc4 0x2f4634 0x1f74ef5 0x128d195 0x11f1ff2 0x11f08da 0x11efd84 0x11efc9b 0x1f737d8 0x1f7388a 0x2f2626 0x264d 0x25b5)
    terminate called throwing an exception(lldb)

     
    • code Mike

      May 12, 2012 at 1:16 am

      Actually, i downloaded the source code for part one and it is working well, but i just want to know the meaning of that error or exception i received.

      Thank you.

       
      • Tim Roadley

        May 12, 2012 at 7:41 am

        Hi Mike,

        That error happens when you have two connections in storyboard to the one property. Did you control drag from the story board to a header file, delete that property then repeat the step? That leaves two connections in connections inspector for the table view controller which causes that error. If you can’t find that double connection I would advise restarting the tutorial again being careful not to repeat any steps.

        I’ll be posting a lot more tutorials in a couple of months when I finish an app I am writing.

        Glad you like the tutorials!

         
  16. code Mike

    May 13, 2012 at 3:27 pm

    Hey Tim,

    You are absolutely right, but i didn’t have to restart the tutorial, I had to just delete the ‘save’ button and create a new one and finally linked it. Everything is okay for now.

    Thanks.

     
  17. Wayne Glass

    May 16, 2012 at 12:43 am

    Thanks so much for your hard work on this tutorial. It was most useful and you did an excellent job explaining the topic. I have learned so much from your tutorial. Thanks again, Wayne

     
  18. Mr. J

    May 16, 2012 at 9:38 pm

    hi tim
    Really great job and very easy tutorials. i successfully copy pasted the code and executed it without any bug :-D

    Tim, i am confused here, today is my first day i am sitting on Mac and doing coding in XCode. just like you said that replace all code in RolesTVC.m (and you gave the code), please can you tell me how i can get understanding of that code? :-) because copy pasting is not enough for me.

     
  19. Danjel

    May 23, 2012 at 8:15 pm

    Thanks a lot for the tutorials! These will be much helpful, as I’m starting to learn Obj-C and Xcode. :)

     
  20. Andrew

    June 8, 2012 at 2:20 am

    Hey Tim! Thanks so much for the tutorials, they are great! I have one problem though. I am trying to have another view that both the UITableViews are accessed by (think central view where processing/calculations are done with a save button and an accessed saved button). This means that I have to have PrepareForSegue in my main view’s viewController. It works fine when I run it, but I get a warning that says Passing ‘MainViewController *const__strong’ to parameter of incompatible type ‘id’

    What does this mean and how would I solve it?

    thanks, Andrew

     
    • Andrew

      June 8, 2012 at 2:27 am

      Sorry, I didn’t include where I got this error.

      It is in the addRoleTVC.delegate = self; line of prepareForSegue. Also, I haven’t added any of the delegation code to my mainViewController implementation or interface files. I did, however #include AddRoleTVC and RolesTVC in the header file for mainViewController.

      Because I didn’t use PrepareForSegue in RolesTVC I now get an Incomplete implementation warning in the implementation file.

       
  21. jonathan3087

    June 23, 2012 at 3:16 am

    Great tut, starting part 2 right now!!

     
  22. Idiot Newbie

    July 1, 2012 at 11:28 pm

    Great tutorial!

    Im fine and follow everything down to:

    Ensure you select UITableViewController and call it RolesTVC:

    Cant find UITableViewController to select…

    Any help would be welcome…

     
  23. Mark Lindamood

    July 4, 2012 at 1:33 am

    I just finished “Core Data Basics Part 1 – Storyboards, Delegation”. I was impressed with how you were able to keep the code clear of peripheral issues (for example, contents for the table itself) so that you could stick to the structure itself (storyboards and delegation.) Thanks for not burying us in code.

     
  24. Bastian

    July 15, 2012 at 11:00 pm

    Hey Tim! Thanks for this great tutorial, but I have a question: Why do you implement a complicated Delegation-Protocol?

    If you want to pop the “AddRoleTVC” just implement this:
    [[self navigationController] popViewControllerAnimated:YES];

    instead of:
    [self.delegate theSaveButtonOnTheAddRoleTVCWasTapped:self];
    … and all the other Delegation-Protocol code.

    Greetings from Germany,
    Bastian

     
    • Jakub

      September 28, 2012 at 11:35 pm

      yeh…I agree with Bastian…and I have the same question on Tim. Thanks for the answer…! Jakub

       
  25. TundraGreen

    July 18, 2012 at 6:37 am

    I have worked through quite a few tutorials. This is probably the clearest, most straightforward, complete and easiest to follow.

    Thanks,
    Will

     
  26. Dee Dee

    July 18, 2012 at 6:46 pm

    Hi Tim,

    I’m adding this to an app with a former ViewController. I don’t know what I’m doing wrong but I keep on getting: “An instance of NSFetchedResultsController requires a non-nil fetchRequest and managedObjectContext”.

    Any idea? Thanks a lot!

     
  27. Bryan

    August 26, 2012 at 11:43 pm

    Hey… I have a really newbie question… I dont have the cocoa touch templates (UIViewController) you were referring to in your tutorial. Where can I download them and how does one install them? Thanks, and keep up the great tutorials!

     
  28. Yimin

    September 26, 2012 at 5:19 am

    Sorry, I got to the part about naming something “Roles” and got completely lost. None of the dragging stuff seems to work.

     
  29. John

    October 4, 2012 at 12:47 am

    Haven’t used storyboards before, this was a great and easy introduction to it, thanks!

     
  30. Jordan

    October 15, 2012 at 11:59 am

    Dear Tim,

    Thanks for all of your tutorials. They are extremely helpful. My problem is that when I assign the AddRoleTVC controller to the custom class, the section, cell, and text field all disappear. I have 2 separate staff manager projects and on one I am up to part 5. All the code works and is correct, however on both projects the same thing occurs in the same area. Hopefully you can help. Thank you!!!

    Jordan

     
    • Jordan

      November 6, 2012 at 4:50 pm

      Also, I’ve found several places that say that static cells will only work with UITableViewController and not with custom classes. If that is true, I would like to know why your project works and mine doesn’t

       
      • Tim Roadley

        November 6, 2012 at 5:57 pm

        You mean why my cells are editable?

         
  31. yaz

    October 28, 2012 at 1:19 am

    hi
    i am new to this world. Can you suggest me how to start with iphone development. I have Lepord loaded with xcode4.2.if possible send me tutorial for creating simple apps using xcode 4.2

     
  32. Alex

    October 29, 2012 at 10:20 pm

    Hi Tim, many thanks for creating easy-follow tutorials. I am using your model of core data and everything is working perfectly. There is one glitch in my added code somewhere, which doesn’t make sense to me. I am displaying data from the database correctly, but when I try to modify the output, it is weird. My cell.detailTextLabel.text displays NSDate. I tried to modify that when the date is from past to display “Expired”, not format 0 years 0months -15days. What happens is, that if the data saved in AddPersonsTVC controller already with past date (UIDatePicker) – the PersonsTVC displays the wrong format 0 years 0months -15days. If you click on PersonDetailTVC and just hit the save button again – the PersonsTVC will give output “expired”. If you click the save button in PersonDetailTVC once more, the result will be “expired” (NULL). Here is the simple code:

    Person *person = [self.fetchedResultsController objectAtIndexPath:indexPath];
    NSString* diastolicValue = [NSString stringWithFormat:@"%@", person.surname];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy/MM/dd"];

    NSDate *futureDate = [dateFormatter dateFromString:theValue];
    NSDate *currentDate = [NSDate date];

    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents *components = [gregorian components:unitFlags fromDate:currentDate toDate:futureDate options:0];

    NSInteger years = [components year];
    NSInteger months = [components month];
    NSInteger days = [components day] + 1;

    //—– TEXT
    NSString *fullname = [NSString stringWithFormat:@"%@ %@", person.firstname, person.surname];

    [cell.textLabel setText:fullname];

    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterLongStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];

    [cell.detailTextLabel setText:[NSString stringWithFormat:@"%i years %i months %i days left",years, months, days]];

    }
    if ( days < 0){

    cell.detailTextLabel.text = @"E X P I R E D";
    }
    if ( months < 0){

    cell.detailTextLabel.text = @"E X P I R E D";
    }
    if ( years < 0){

    cell.detailTextLabel.text = @"E X P I R E D";
    }

    I used to use this code in my previous version (non-storyboard) and it worked fine. Expired sign was displayed right after you saved the past date. What am I doing wrong here please? Many thanks for your time and advice.
    Alex

     
    • Alex

      October 31, 2012 at 10:43 am

      All sorted! I made another strings and it is working fine! Sorry to filling the space here. Amazing tutorial though!!! Many many thanks!

       
  33. Robert

    October 30, 2012 at 8:16 pm

    Ohh, this tutorial is so f good! Congratulations!

     
  34. nwebbebb

    November 25, 2012 at 6:54 pm

    Tim, excellent, clear tutorial – much appreciated!

    I’m coming to iOS fresh from another language and I documented a few things to help my understand the process better – it may provide further clarification to others, so I’ll paste it below :)

    //AddRoleTVC.h file (Xcode 4.5.2)

    //This seems to be a slight change – Xcode now specifically imports UIKit
    #import

    //This is simply a compiler directive to withhold errors (i.e. we tell Xcode the Class will be declared
    //later and not to throw an error
    @class AddRoleTVC;

    //The angled brackets below means that AddRoleTVCDelegate’s protocol in turn conforms to
    //NSObject’s protocol.
    //Why do this? Because NSObject implements ‘respondsToSelector’, and this method can be used
    //to ensure our delegate object implements any optional methods before we call them
    //(thus avoiding possible runtime crashes)
    @protocol AddRoleTVCDelegate

    //it is best to be explicit about whether each method is required or optional
    @required
    -(void) theSaveButtonOnTheAddRoleTVCWasTapped: (AddRoleTVC *)controller;
    @end

    @interface AddRoleTVC : UITableViewController

    //We want to be able to use any object-type for our delegate so we declare it as ‘id’
    //However, our object must also adhere to our protocol. The angled brackets
    //specify that whatever object we point to must do this.
    @property (nonatomic, weak) id delegate;

    -(IBAction)save:(id)sender;

    @end

     
  35. Adriano Gonçalves (@amg1976)

    November 29, 2012 at 12:51 am

    Hi. I have been working with iOS for a couple of years but it’s the first time I’m looking into Core Data and Storyboards.
    Really enjoyed this first part, when I finish the complete tutorial I will give you a more detailed feedback… but so far I’m liking it a lot! :)

     
  36. Stuart

    December 14, 2012 at 2:34 pm

    Hi Tim, really nice tutorial.
    Sorry but i am newbie Ios programmer, so i haven’t find how to Reload the table to see the role added, i used refreshControl but didnt work, hope u help me.
    Thank u!!!

     
  37. German

    May 19, 2013 at 9:30 pm

    Great Info!. thx.

     

Leave a Reply