Storyboards Segue Tutorial: Pass Data Between View Controllers

102 Flares 102 Flares ×

This is the second article of our Storyboards series. In the first tutorial, we introduced the Storyboards, which is a friendly feature in Xcode for designing user interface. If you’ve followed the tutorial from start to end, you should already build a simple recipe app with navigation interface. But we left one thing that was not discussed: data passing between scenes (i.e. view controllers) with segue.

First, let’s take a quick look at what we’ve accomplished. Previously, we learnt to use Storyboards to build a few things:

  • Embedded a normal view controller in navigation controller
  • Created a table view and populate a list of recipes
  • Switched from one view controller to another view controller using Segue

And, this is the final deliverable. When the app is launched, it displays a list of recipes. Tap on any of them will bring you to another view, that supposes to display the details of recipes.

Receipe App With Detail Controller

Receipe App with Detail Controller

We didn’t implement the detail view which now shows a static label. So we’ll continue to work on this project and polish the app.

Assigning View Controller Class

In the first tutorial, we simply create a view controller that serves as the detail view of recipe in the Storyboard editor. The view controller is assigned with the UIViewController class by default.

Default View Controller

Default View Controller - UIViewController

Let’s revisit our problem. The label in the view should be changed with respect to the selected recipe. Obviously, there must be a variable in the UIViewController for storing the name of recipe.

The fact is the UIViewController class only provides the fundamental view management model. It corresponds to a blank view. There is no variable assigned for storing the recipe name. Thus, instead of using UIViewController directly, we extend from it and create our own class (known as the subclass of UIViewController).

In the Project Navigator, right-click the “RecipeBook” folder and select “New File…”.

Storyboard New View Controller

Create New File in Xcode Project

Choose “Objective-C Class” under Cocoa Touch as the class template.

Storyboard New ObjectiveC Class

Select Objective C Class

Name the class as “RecipeDetailViewController” and it’s a subclass of “UIViewController”. Make sure you uncheck the option of “With XIB for user interface”. As we’re using Storyboards for designing the user interface, we do not need to create a separate interface builder file. Click “Next” and save the file in your project folder.

Storyboard New RecipeDetailViewController Class

Create a RecipeDetailViewController class (Subclass of UIViewController)

Next, we have to assign the RecipeDetailViewController class to the view controller. Go back to the Storyboards editor and select the detail view controller. In the identity inspector, change the class to “RecipeDetailViewController”.

Storyboard Change View Controller Class

Change View Controller Class

Adding Variables to the Custom Class

We’ve just created our custom view controller class by extending from the UIViewController class. However, it doesn’t differ from the parent class until we add our own variables and methods. There are a couple of things we have to change:

  • Assign a variable (recipeName) for data passing – when user selects a recipe in the Recipe view, there must be a way to pass the name of recipe to the detail view.
  • Assign a variable (recipeLabel) for the text label – presently the label is static. It should be updated as the name of recipe changes.

Okay, let’s add these two variables (recipeLabel and recipeName). Select the “RecipeDetailViewController.h” and adds two properties for the interface:

@interface RecipeDetailViewController : UIViewController

@property (nonatomic, strong) IBOutlet UILabel *recipeLabel;
@property (nonatomic, strong) NSString *recipeName;


Go to the “RecipeDetailViewController.m” and add the synthesis for the variables. Make sure you place the code under “@implementation RecipeDetailViewController”:

@implementation RecipeDetailViewController

@synthesize recipeLabel;
@synthesize recipeName;
If you’ve forgotten what the interface and implementation are, go back to this tutorial and revisit the concept.

Establish a Connection Between Variable and UI Element

Next, we have to link up the “recipeLabel” variable with the visual Label. In the Storyboards editor, press & hold the command key and then click the “Recipe Detail View Controller” icon, drag it to the Label object. Release both buttons and a pop-up shows variables for your selection. Choose the “recipeLabel” variable.

Storyboard Recipe Detail Link Variable

Establish the Connection between UI element and Variable

That’s it. Now you’ve linked up the variable with the Label UI element. Any change in the variable will be reflected visually. But there is still one thing left. We want to have the label to display the recipe name. So in viewDidLoad function, we add the following code that sets the label text the same as the recipe name.

- (void)viewDidLoad
    [super viewDidLoad];
    // Set the Label text with the selected recipe
    recipeLabel.text = recipeName;

Try to compile and run your app. Oops! The detail view is completely blank after selecting any recipe. That’s the expected behavior. We haven’t written any code to pass along the recipe name. Yet, the “recipeName” variable is blank that contributes to the empty text label.

Receipe App With Empty Detail Controller

Receipe App with Empty Detail Controller

Passing Data Using Segue

This comes to the core part of tutorial about how to pass data between view controller using Segue. Segues manages the transition between view controllers. On top of this, segue objects are used to prepare for the transition from one view controller to another. When a segue is triggered, before the visual transition occurs, the storyboard runtime invokes prepareForSegue:sender: method of the current view controller (in our example, it’s the RecipeBookViewController). By implementing this method, we can pass any needed data to the view controller that is about to be displayed.

However, the best practice is to give each segue in your Storyboards an unique identifier. This identifier is a string that your application uses to distinguish one segue from another. As your app becomes more complex, it’s likely you’ll have more than one segue in the view controllers.

To assign the identifier, select the segue and set it in the identity inspector. Let’s name the segue as “showRecipeDetail”.

Storyboard Segue Identifier

Storyboard Segue Identifier

Next, we’ll implement the prepareForSegue:sender: method in “Recipe Book View Controller”, which is the source view controller of the segue. Select the “RecipeBookViewController.m” and add the following code:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        RecipeDetailViewController *destViewController = segue.destinationViewController;
        destViewController.recipeName = [recipes objectAtIndex:indexPath.row];

The prepareForSegue method will be called when the transition begins. The 1st line is used to verify the identifier of segue. In this case, the identifier is “showRecipeDetail”. The 2nd line of code invokes the tableView:indexPathForSelectedRow to retrieve the selected table row. Once we have the selected row, we’ll pass it to the RecipeDetailViewController. A Segue object contains the view controller whose contents should be displayed at the end of the segue. You can always use “segue.destinationViewController” to retrieve the destination controller. In this case, the destination controller is the RecipeDetailViewController. The rest of the code is to pass the recipe name to the destination controller.

You can’t run your app right now. After you copy & paste the above method into RecipeBookViewController.m, you should see a number of errors.

Storyboard prepareForSegue Error

prepareForSegue Error

There are three errors as shown above. But we can summarize them into two:

  • The property “tableView” is not found in RecipeDetailViewController.
  • What’s RecipeDetailViewController? Xcode doesn’t know what it is.

Let’s talk about the second error first. In RecipeBookViewController, it has no idea about RecipeDetailViewController. In Objective C, you use the “#import” directive to import the header file of other class. By importing the header file of “RecipeDetailViewController”, RecipeBookViewController can access the properties and methods of the detail view controller. Place the following code at the very beginning to fix the error:

#import "RecipeDetailViewController.h"

Regarding the first error, you should know how to fix it. This is similar to the Label UI element we discussed earlier. There should be a corresponding tableView variable that connects with the UI element.

So, in the RecipeBookViewController.h, add the following code before “@end”:

@property (nonatomic, strong) IBOutlet UITableView *tableView;

For the RecipeBookViewController.m, add the synthesis directive to tell the compiler to generate the accessor methods for the tableView variable.

@implementation RecipeBookViewController {
    NSArray *recipes;

@synthesize tableView; // Add this line of code

Lastly, go back to the Storyboards and link up the variable with the UI element. In the “Recipe Book View Controller”, hold the command key and click the view controller icon, drag it to the table view. Release both buttons and select “tableView”.

Storyboard Connect TableView

Establish connection with the tableView variable

Now, all the errors should be resolved. Let’s try to compile and run the app. This time, your app should work as expected. Try to select any recipe and the detail view should display the name of the selected item.

Recipe App With Correct Detail View

Recipe App - Our Final Deliverable

What’s Coming Next?

Isn’t it easy to build an app with navigation interface? With the introduction of Storyboard, it significantly reduces the amount of code you need to deal with. Most importantly, the centralized Storyboard interface provides a high-level overview about the flow of the app. I hope these two tutorials gives you an idea about how Storyboard works and how you can make use of it to build your own app. Though the app we’ve created is simple and with an elementary UI, it elaborates the fundamental concept that you can base on it to build more complex app.

In the later tutorials, we’ll explore the static table cell and continue to make the app even better with tab controller. Stay tuned and make sure you leave us comment below if you have any questions.

Update: You can now download the full source code for your reference.

You May Like These:

Get Free Chapters of Our AppCoda Book

Learn iOS 7 Programming from Scratch

The Learn iOS 7 Programming from Scratch is a 400-page eBook written for beginners with little or even no programming experience. It is based on the tutorials of our popular programming course. The book starts with the basics and walks you through the process to create iOS apps using iOS 7 SDK and Xcode 5. Want to learn more? Check it out here and get two free chapters.

Build Your Own Game and Monetize on the Side

Learn how to develop your first iOS game and make money on the side. The starter kit will come with full source code of a memory game for both iPhone and iPad, as well as, a complete guide to explain how the code works. Check out the starter kit to learn more.

  • Alan Tong

    Just read through the tableview and storyboard tutorials. Great work! Keep it rolling!

    • Simon Ng

      Glad to hear that! :-)

      • Raghavendra

        simon sir …….can i get sms and mail composing and sending applications complete code details from u plssssssssssssssssssssssssssss……………………..

  • kash56789

    Hi simon,
    great tutorial again.. I have a few doubts regarding this..
    1. First is, how to use multiple segues for different cells(rows) of the recipeBookViewController? I want to show different DetailViewControllers for different recipes that a user selects.
    2. second doubt i have is, how can i have support for the user to edit the details of a recipe, basically, if the user taps on a recipe, he will get to see a specific detailviewcontoller in which he can give a rating for that recipe. Now how can i add this? And how can i get the data back from the detailViewController back in the RecipeBookViewController?

    • rashmi mohammed

      i want quiz app source code with database connection pl anybody send me plzzzzzzzzzzzzzzzzzzzzzzzzzzz

  • Ajit

    Thank You very much..!!!!

  • Betti

    Hi, thank you for the GREAT Tutorial!!!
    My suggestion: Recipe Favorites in a tabbar.
    I mean recipes in detailview to highlight and then show a list of favorites in a new viewcontroller. Through such a tutorial would be very happy! Think about for months how to do it. Is it possible to make such a tutorial?
    Or another idea: A shopping list would be great too!
    Best regards Betti

    • Simon Ng

      @3698f894c6d2328618c1b51f185ce9d0:disqus that’s good suggestion. In future tutorials, I’ll show you how to implement a list of favorite recipes. By the way, I’ve just published a new post about how to create the tab bar interface. Check it out here:

      • Betti

        @fae42a323f80bb60e27e7a0d08e19afa:disqus That would be really great!!! I’ve been trying for months to make a favorites list, unfortunately without success. I’m really looking forward to this tutorial. It would be really great if you explain this with an example with a Property List! I hope it’s come soon … Maybe you can tell me when can I hope for the tutorial? Your tutorials are really explained very well. Greetings Betti

  • James

    Good tutorial! I have one question though. What if you wanted to display specific information about that particular cell that the user touches within the detail view?

  • James

    Hey thanks for the reply. What I meant though was like you know how the contacts app lets you select a certain cell and display content related to that cell. So like you have a table view and detail view. The table view has 3 cells. cell1, cell, 2 and cell 3. When you click on cell 1 you navigate to the detail view which shows a label ; ‘welcome to cell 1′ and a description like ; ‘welcome to the first view’. How do you do all this within one detail view controller?

  • Pingback: Storyboards Segue Tutorial: Pass Data Between View Controllers | Ten Horses

  • NewComer

    I have an error, I’m very new to this and just started learning this week. Everything works but the Label doesn’t show the actually names, it is still ‘label’.

    The error says ‘Local declaration of ‘tableView’ hides instance variable’
    ‘ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];’

    Just a bit confused now, Ive tried going through it all again but it still comes up with the error, I have a feeling I’m messing up somewhere.

    • Ed B.

      Did you ever get an answer to your question? I am having the same problem.

    • 4ki

      Did you solve your issue? I have the same issue and when I run Simulator Recipe Detail View Controller screen become black. Anyone can help?

      • shivank

        hey u just connect the view to the label in receipe detail view controller so u just remove it and see the magic if not than concern to me !!!

    • shivank

      hey u just name the tableView with tableView1 in ur property and changed acc to that in ur program !!!

      • Dustin

        Hi I had the same error and changed the tableView to tableView1 just like you said, but I got another error…
        Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.’

        quite frustrated, could you help? Thanks

        • Tom Mutdosch

          Got this too. This issue is likely because you’ve accidentally defined an outlet in Interface Builder to a missing property. I did this because I had accidentally added an outlet in the RecipeDetailViewController instead of the RecipeBookViewController. I deleted the generated property from the .m file, but apparently the outlet connections remain. Had to remove them via Interface Builder and all was good.

    • Doug Folland

      should be:

      UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

      • napolux

        That solved the problem. Thanks!

      • iTouchGamer31

        This got rid of the error, but the App still runs with a black screen….

        • marlee32

          Did you manage to fix this?

  • Sean

    Fantastic set of Tutorials. Im a newbie to Object Oriented programming and very new to concepts of programming in iOS and have found the entire set very helpful indeed.

    I’ve run this tutorial and everything works great other than getting a compile time issue saying “Local declaration of ‘tableView’ hides instance variable”.

    I’ve added the @synthesize tableView so not sure what the compiler is trying to warn me of. Is this meant to happen?

    Thanks for a great blog.

  • sanz

    thanx for such an awesome tutorial it has helped me alot to rise from a begginer

  • rus

    Recipe Book list is empty but everything else works great,

  • Nazmul

    Many thanks for such awesome tutorial. This works for me. Much appreciate. Please keep it up. Thanks again!

  • Vibhor

    I have been through many tutorials, but I think this is the most basic approach to teach a beginner. The way you have written this tutorial is imply AWESOME!! It really is a pleasure going through your tutorials. Thanks. Thanks a lot. And Keep it up!!

    • Simon Ng

      Thanks. What a compliment! More tutorials are coming :-)

  • Tejasvi

    Very nicely done, very useful.

  • Pascal

    Thanks for sharing – very nice.
    could you also do a master/detail app tutorial for iPad, where every clicked cell loads a different HTML page in the detail screen?
    Thanks very much

  • iPhoneHome

    I am having the same error as : The error says ‘Local declaration of ‘tableView’ hides instance variable’
    ‘ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];’

    Also, I changed the NSArray *blogs; instead of receipes and I am getting this error.
    Use of undeclared identifier ‘blogs’

    Thanks in advance.


    • tcm692

      I’ve found that if you put self. in front of the tableView dequeueReusable…, that will take care of the first error.
      As far as your second error, you will have to go through all of your code and everywhere there is recipes, you’ll need to change it to blogs.

      Hope this helps.

    • rajohns

      for the first warning about local declaration, if you put @synthesize tableView = _tableView it should correct the warning. This keeps the compiler from complaining that it can’t see the instance variable inside a function that has the same variable name.

      • Waboab

        “@synthesize tableView = _tableView”
        Did the trick rajohns, Thanks

    • Connected Cat

      UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

      this is what that line should look now. tableView was declared in the .h file making it a property of the class. Since we’re inside that class (RecipeBookViewController) – in order to call on that property you need to address it via self.’propertyname’

  • Vijay

    Hi Greetings

    I would like to Pass data to a table view controller and update the detail label in a Table cell.
    When I click on the tableviewcell, it will navigate to a UIViewController where I enter text and navigate back. When I naviagate back I would like to update the detail label on the textview with the text entered in the UIViewController.

    How can this be done. Can you please provide a tutorial on this.?

  • Pingback: Improve the Recipe App With a Better Detail View Controller | iptips - iphone / ipad / ios / android / mobile / tutorials

  • Pingback: Improve the Recipe App With a Better Detail View Controller | hatforrent

  • Pingback: Improve the Recipe App With a Better Detail View Controller | t1u

  • wilky

    I still have an error saying that the property could not be found…

    • Simon Ng

      which property?

      • Billy

        The property for recipeName in the segue -(void) call. It doesn’t seam to be able to be imported from the detail.h. I can’t seam to get it to work.

  • Pingback: 第十一部分:Storyboard 联线教程-在视图控制器间传递数据 | 技术分享平台

  • Joonho Lee

    Thanks for great tutorial. I have learnt a lot from your site. It’s really helpful to me. One thing I want you ask is at the very last part, I got problem to display detail information of various table view rows other than first row. For example, if I selected second row named “Mushroom Risotto”, I still got “Egg benedict”. I did all you have done in my project. Please let me know what I missed. Thank you again.

    • Manju

      I have the same problem too.. Let me know how it can be resolved

    • fbrska

      me too. anyone has figured out the solution?

    • fbrska

      me too. anyone has figured out the solution?

    • Charlie

      Unfortunately, I have the same problem here. I am assuming it’s a side effect of using tableView twice, and then having to go back and fix that by giving each a different name. However, after fixing that, I have the same issue – the details tab always shows Eggs Benedict.

      I haven’t seen a response from the author yet… hopefully we’ll see something soon.

    • Untitled Entitled

      I’m having the same issue. Not sure what’s going wrong.

    • John Kealy

      I took this tutorial a week ago, got stuck on this exact issue then took some online courses, now I’m back with an answer!
      Go into storyboard and open up your “split editor” with story board on left and code on the right. Click on table view and drag it into the code, select

      @property (nonatomic, strong) IBOutlet UITableView *tableView;

      re-run and hopefully no more eggs benedict!

  • Aaron Huang

    It is an awesome tutorial! I have a question. I followed your another topic which guided me to add a customized Cell. How could the customized cell push from the table to the detail controller? Many thanks!

  • erhandemirci

    this tutorial Great :)

    if you want tutarial , project in github ,

    enjoy programming :)

  • abbiya

    :) please write more

  • Tyler

    could you do a tutorial on how to group the items in the table view controller?

  • Pingback: Things I Learned in October « Software Ramblings

  • Pingback: Storyboards Segue Tutorial: Pass Data Between View Controllers «

  • marlee32

    I keep getting an Error with this line:

    int main(int argc, char *argv[])

    @autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([SimpleTableAppDelegate class]));

    It says Program received signal ‘SIGABRT’

    • Bryan Lee

      Hi I wonder if you manage to solve the problem?
      I got the same error too :D

  • marlee32

    Are you able to post the completed code for each of the files up, so I can see where I’ve gone wrong?

    Thanks in advance,


  • Oscar

    Great tutorial. This is exactly what Apple is missing when delivering their Dev environment.


  • Pingback: Sample iPad app to work with JSon based Machine Learning System | GoSmarter Tech Blog

  • Arwin

    i declared @synthesize newView;

    next to @implementation Viewcontroller

    iam getting a error “property implementation must have its declaration in interface viewcontroller ”

    give me a solution….

  • fthozt

    great tutorial. thanks a lot

  • magero

    Thank you for the tut, but i need that first row of the table view goes to another detailview. Please help. Thanks

  • Jyotiranjan Rout

    Hi,I’m adding recipe like this:

    In view did load….
    arrReceipes = [[NSMutableArray alloc] init];

    NSArray *arrReceipesTime1 = [NSArray arrayWithObjects:@"Half an hour or less",@"About an hour",@"More than an hour", nil];

    NSDictionary *arrReceipeTime1Dict = [NSDictionary dictionaryWithObject:arrReceipesTime1 forKey:@"Find Recipes"];

    NSArray *arrReciepHeart = [NSArray arrayWithObjects:@"HealthyAndDelicius", nil];

    NSDictionary *arrRecipesHeartDict = [NSDictionary dictionaryWithObject:arrReciepHeart forKey:@"Find Recipes"];

    NSArray *arrRecipeLifestyle = [NSArray arrayWithObjects:@"Recipe for fall",@"Quick and easy",@"Cooking for kids",@"Easy entertaining",@"American classics",@"Outdoor cooking", nil];

    NSDictionary *arrRecipeLifestyleDict = [NSDictionary dictionaryWithObject:arrRecipeLifestyle forKey:@"Find Recipes"];

    [arrReceipes addObject:arrReceipeTime1Dict];

    [arrReceipes addObject:arrRecipesHeartDict];

    [arrReceipes addObject:arrRecipeLifestyleDict];

    And I referred your code to pass value using segue like following:

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sende


    if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {

    NSIndexPath *indexPath = [self.tableView1 indexPathForSelectedRow];

    RecipeDetailViewController *destViewController = segue.destinationViewController;

    destViewController.recipeName = [arrReceipes objectAtIndex :indexPath.row ];



    if I comment code “destViewController.recipeName = [arrReceipes objectAtIndex :indexPath.row ];

    My application working fine , but I’m not able to see the selected value in “label”

    But, with this code in place : “destViewController.recipeName = [arrReceipes objectAtIndex :indexPath.row ]; I’m getting exception in “main method”…Please let me know where I’m going wrong.Thanks.

  • Mark Thien

    awesome tutorial ! it would be great if you can extend to get the table row data from a plist file in order to make it dynamic. however, I can write it up if you allow

  • tom

    Hi there. Great tutorial. Got it working no problem. What I want to do is have the detail view controller as another table view that is populated with different data based on which cell of the first table view has been pressed. For example, if ‘eggs benedict’ was pressed it would bring up a new table with cells ‘eggs’ and ‘benedict’ which in turn could be pressed. However if ‘mushroom risotto’ was pressed then if would return cells ‘mushroom’ and risotto’ etc etc. Can anyone help me out or point me in the right direction of a good tutorial please. Thanks. Tom

  • Tim

    Hi there, thanks BTW! — How come in my DetailViewController page it’s aways showing “Egg Benedict”? no matter which recipe I choose from the MainViewController :( Thanks!!

  • Samuel Quiring

    Did you mean “control key” instead of “command key”?:

    Next, we have to link up the “recipeLabel” variable with the visual Label. In the Storyboards editor, press & hold the command key and then click the “Recipe Detail View Controller” icon, drag it to the Label object. Release both buttons and a pop-up shows variables for your selection. Choose the “recipeLabel” variable.

  • Tim

    Hi Simon, hope you can help. just did the “Storyboards Segue” Tutorial. How come in my DetailViewController page it’s aways showing “Egg Benedict”? no matter which recipe I choose from the MainViewController :(

    I’ve even put in a NSLog(@”indexPathrow:%d”,indexPath1.row); in my prepareForSegue and no matter which row i select, it’s still showing row = 0. What am I doing wrong? the code portion seems right, could it be something in the storyboard?? THANKS SO MUCH!

  • Lauren Mccrea

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id) sender {
    !Use of undeclared identifier ‘prepareForSegue’

    What am I missing? Help

  • bugger

    How i can pass Data with seque and an custom cell? i have a custom cell and i can’t pass the data. the push doesnt work.

  • jagan

    nice tutorial, the new learners also can understand easily this tutorial. thanks a lot for it.

  • Fan

    Thanks for yr tutorial, very good and easy to follow

  • carl

    I get this error message:-[MPConcreteMediaItem isEqualToString:]: unrecognized selector sent to instance…

    I am creating an NSMutable array of songs from media picker into an array named “array”. This array shows up properly in the tableview (myTable). HOWEVER when I try to segue to the detail view and send the song title to a label on the detail view following this tutorial. I get the crash and error message above.

    Appreciate any help, thanks!

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([[segue identifier] isEqualToString:@”detailView”]) {

    NSIndexPath *indexPath = [self.myTable indexPathForSelectedRow];

    DetailViewController *vc = [segue destinationViewController];

    vc.trackName = [array objectAtIndex:indexPath.row];

    //crashes -[MPConcreteMediaItem isEqualToString:]: unrecognized selector sent to instance



    - (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection


    // [self updatePlayerQueueWithMediaCollection: mediaItemCollection];

    [array addObjectsFromArray:mediaItemCollection.items];

    [[GVMusicPlayerController sharedInstance] setQueueWithItemCollection:mediaItemCollection];

    [[GVMusicPlayerController sharedInstance] pause];

    [myTable reloadData];

    // mediaItemCollection = nil;

    [mediaPicker dismissViewControllerAnimated:YES completion:nil];


    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath


    //this method is called to fill out table with data

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    if (cell == nil)


    cell = [[UITableViewCell alloc]




    // Configure the cell

    anItem = nil;

    anItem = [array objectAtIndex:indexPath.row];

    cell.textLabel.text = [anItem valueForProperty:MPMediaItemPropertyTitle];

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

    return cell;


    • carl

      This solved the problem:
      NSIndexPath *indexPath = [self.myTable indexPathForSelectedRow];

      // Reference to destination view controller

      DetailViewController *vc = [segue destinationViewController];

      MPMediaItem *songToPlay = [array objectAtIndex:indexPath.row];

      NSString *titleString = [songToPlay valueForProperty:MPMediaItemPropertyTitle];

      vc.trackName = titleString;

  • Hugh Jeremy

    I have a quick question, when you press something it highlights blue. This is fine when it goes to the next view controller, however when you you go back to the first view it is still selected, how can I make it so that it is not highlighted when you go back? Thanks Hugh

  • Jubee

    please tell me how edit this code:to select one of table view it will show detail and when select other rows it will show in differences details. Thanks

  • Tatyana

    I got error: NSArray *recipes Not an Objective-C object

  • furlan

    Hello! Great tutorial! Thanks for creating it. But I have 1 question, after the detail view controller i added a new view controller and did the same to connect it to the detail view, but it won’t work, when i click an item that is suppose to show the new view nothing happens. can you help me with this one?

    • furlan

      by the way, im using another table on the detailviewcontroller

  • Urs

    Good Tutorial, but what do I have to do that the title of the DetailView shows the recipename instead the label?

  • Jumanji

    many thanks great tuts!!!

  • Ali Jaffar

    Simply the best IOS Tutorials out there on the net :) Thank a bunch for this effort and keep em coming Simon :D!

    AJ From Pakistan :)

  • iOSnewbie

    Great tutorial, very clear.
    What if you created a button on the recipe detail view and wanted it to segue to a new VC with a web view, how do you pass a string to this 3rd VC that corresponds to the data from the 1st VC (the recipe book)?

    I made an array of dictionaries, populated the table view then passed 4 keys to the detail view. I want to give a button on this detail view one of the keys, which is a URL, so when you press the button it pulls up a website corresponding to the selected dictionary.

  • vendi

    I tried it out but got warning in my main.m file as “signal SIGABRT”….
    i can’t solve it out….
    plssssssss…… any one help me out….. :(

  • Sachin

    Great tutorial its help me alot …. thumbs up

  • BJames

    Great tutorials, my app also always shows egg benedict as many have mentioned. Reply?

  • Sankaet Pathak

    Great tutorials guys! but Why aren’t you guys using assistant editor? so that we can just hold control and drag objects within the interface so that properties are created automatically? that would be a way easier way of going about it. Dont you think?

    also, it would be really helpful if you include the part where how to get rid of the blue selection of the cells once we click the back button.

  • Vaibhav Aggarwal

    Thank you so much for this tutorial! I really appreciate you for helping everyone out!

  • Brock

    Worked first time,,, easily understood your concept….Thank you…Great Instructor……am your Fan now :)

    • Simon Ng

      Thanks! Great to hear that :-)

  • vishnu

    In the “Recipe Book View Controller”,i hold the command key and click the view controller icon,and drag it to the table view. Release both buttons and i have only “view” not “tableView”.i done each and every step through your instruction only. i don’t know why “tableview” not appear.please help me.

    • Erin Parker

      It’s a typo. You should be holding the Control key.

      “In the “Recipe Book View Controller”, hold the command key and click the view controller icon…” this should say “hold the control key”.

  • LittlePeculiar

    Great tutorial. I have been programming iOS for years but lack of time and an innate resistance to change :) kept me from learning Storyboard. This was an easy and fun little app. I’m off to recreate some older apps for practice. Thanks.

    • Simon Ng

      That’s great! Look forward to the release of your apps.

  • Khalid Mehmood Awan

    Excellent way !!!!! nice tutorials….
    I wish for every tutorial , you also attach the project/solution zip file…

    • Simon Ng

      All the new tutorials come with the Xcode project. For the old tutorials, I’ll try to upload the project files later.

  • Billy

    Having a problem with the “RecipeName” NSString. I imported it to the RecipeViewController.h but in my .m in this piece ->destViewController.recipeName = [characters objectAtIndex:indexPath.row]; it is saying recipeName is not found in. Any ideas?

  • Mugunthan

    how can you pass a variable from the child VC to the Parent VC

  • Colinch

    The app works and compiles but when I click on a recipe I have an error in the main.m it says:

    Thread 1: signal SIGABRT

    in this selection:

    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

    I’m using the object orientated version for this tutorial so maybe it’s because of that.

  • Colinch

    The app works and compiles but when I click on a recipe I have an error in the main.m it says:

    Thread 1: signal SIGABRT

    in this selection:

    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

    I’m using the object orientated version for this tutorial so maybe it’s because of that.

  • Alyssa DeChiaro

    I used this tutorial to be able to click a Table Cell to open up to a new View. However I just used a plain View instead of a Label. I’m using the contents of a database that is accesed from a local server so the data is not hardcoded as it was for this example. So my question is, how can I get different data from my database to be seen in the DetailViewController as well?

  • a NewCoder

    My label is not changing its text….it just stays the same as what I constructed it as in the beginning

  • Carlpitro

    Hello Simon, in the past few years i started, stopped on and on trying to learn IOS development. Your tutorials are the best I came across and now for the first i feel like making progress. Thanks…

    • Simon Ng

      Thanks for your kind words. It’s great to hear that you find the tutorials are helpful.

  • Mac Mani

    Yours all tutorials are very clear explanation with very good road map, easily can understand the words, today i found a nice tutorial. Thanks, thanks a lot.

  • shailesh

    Nice tutorial :)

  • khanhtungna

    Please help,

    I have declare the variable tableView in RecipeBookViewController
    @property (nonatomic, strong) IBOutlet UITableView *tableView;

    2/ I added it in RecipeBookViewController.m
    @synthesize tableView;

    3/ In RecipeDetailViewController.m
    I have imported RecipeBookViewController.h

    But still got the error “Property tableView not found on object RecipeDetailViewController”

    Any advices for me?

  • Anne-So


    I’m sorry for my English, I’m french ;)
    I have a question, if I want to do the same with “textField”, have you got a solution ?
    Thanks for your tutorials, I’m in placement and your tuto save my life ^^

    Thanks in advance :)

  • cong nguyen

    thanks a lots :)

  • HLA

    good tutorial….

  • Ohm Attaphong

    For guys who faced the problem that DetailViewController page aways showing “Egg Benedict”, please don’t forget to bind the RecipeBookViewController to tableView outlet. You can do it by click at the RecipeBookViewController and control+drag to table view then select tableView.

    • Massiel Legot

      Thanks @Ohm Attaphong:disqus , perfect!

    • Fegol

      Thanks a lot!!!

  • jadacoast

    Thank you so much for all of these – not sure what I’d do without them! They’ve been challenging for me but I’ve managed to get there in the end :-)

  • hitesh

    things here are explained very simply… fantastic article…

  • Nic

    Thanks for ur wonderful tutorial. it works and solves my long time problem. I really appreciate it.
    Will we have a tutorial for implementing multiple sections in tableView ?? That will be great !!

  • k0e3

    I don’t get the very last part about linking the table view. Why do we all of a sudden need to do that when things pretty much worked in the table view prior to that?

  • bshih11

    how to you make program it so that when you click a button, it turns to the next view on storyboard?

    • Simon Ng

      It’s similar to what we have done here. You have to create segue between the button and the view.

  • Ace

    Great Tutorial…Thanks a lot…

  • JAD11441

    Awesome tutorials! Question-
    what does the line …. = segue.destinationViewController accomplish? What would happen if you instead said:

    RecipeDetailViewController *destViewController = [recipeDetailViewController alloc] init]; or something like that.

  • Nils

    Hi, I am using Xcode 5. The making connection step between “Variable” and “UI Element” turns to “Press control and hold” + ….

    Great tutorial, the best I have ever seen!


  • Jitender Singh

    thanks a lot, these is very helpful for me. thanx again.

  • Ankit

    Please help,

    I have declare the variable tableView in RecipeBookViewController
    @property (nonatomic, strong) IBOutlet UITableView *tableView;

    2/ I added it in RecipeBookViewController.m
    @synthesize tableView;

    3/ In RecipeDetailViewController.m
    I have imported RecipeBookViewController.h

    But still got the error “Property tableView not found on object RecipeDetailViewController”

    Any advices for me?

    • Austin

      tableView property goes on RecipeBookViewController, not RecipeDetailViewController.
      BookView may import DetailView to get a destination view.

    • Carl

      In step 3, I think you have it backwards.
      You need to import RecipeDetailViewController.h in RecipeBookViewController.h

  • Pingback: Updating UILabel through TableView Segue throws unrecognized selector exceptionQueryBy | QueryBy, ejjuit, query, query by,, android doubt, ios question, sql query, sqlite query, nodejsquery, dns query, update query, insert query, kony, mobiles

  • Pingback: Updating UILabel through TableView Segue throws unrecognized selector exceptionCopyQuery CopyQuery | Question & Answer Tool for your Technical Queries,CopyQuery, ejjuit, query, copyquery,, android doubt, ios question, sql query, sqlite q

  • Pingback: Updating UILabel through TableView Segue throws unrecognized selector exception - |

  • HEY

    THANK YOU :)

  • Rick Mann

    You mean “control” key, not “command” key, don’t you?

  • uncle Sam

    I’m having a sigabrt while selecting the row for the push to the next page….want it could be?
    I’m mergin’ the two type of tutorial (prototype cell and this one) into one and everything was fine until now.
    the functions seems right written and i’ve no errors or warning…

  • abDullah

    It would be very helpful if you can add a small homework at the end of each totourial …… Again thanks a lot :)

  • Mạnh Hiền Lành

    good job! thanks for guide article, i hope than more tutorial as this, i’m waiting…

  • Young

    What if you want to show thumnail pictures for each recipe in detail view controller?

    It’ll be perfect if I can use .plist file for that.

  • Pingback: After segue animate label to new x origin |

  • Pingback: Passing data between views and segues | Xcode iOS and OSX Tutorials

  • Magesh

    I am a new developer learning iOS Programming with iOS 7 and Xcode 5. I am trying to show the preptime and images as well as in the detail view. I am able to get the prep time displayed but not the image. Here is the detail of my work, any suggestion would be much appreciated.

    1) properties declared in detailviewcontroller.h

    @property (nonatomic, strong) IBOutlet UILabel *recipeLabel;
    @property (nonatomic, strong) NSString *recipeName;

    @property (nonatomic, strong) IBOutlet UILabel *prepTimeLabel;
    @property (nonatomic, strong) NSString *prepTime;

    @property (nonatomic, strong) IBOutlet UIImageView *recipeImageView;
    @property (nonatomic, strong) UIImage *recipeImage;

    2) above properties are defined in detailviewcontroller.m as below

    - (void)viewDidLoad
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.recipeLabel.text = self.recipeName;
    self.prepTimeLabel.text = self.prepTime;
    self.recipeImageView.image = self.recipeImage;


    3) Table view is linked thru segue as per the below

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    if([segue.identifier isEqualToString:@"showRecipeDetail"]){
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    RecipeDetailViewController *destViewController = segue.destinationViewController;
    destViewController.recipeName = [recipeNames objectAtIndex:indexPath.row];
    destViewController.prepTime = [prepTimes objectAtIndex:indexPath.row];
    destViewController.recipeImageView = [recipeImages objectAtIndex:indexPath.row];

102 Flares Twitter 14 Facebook 64 Google+ 20 LinkedIn 4 102 Flares ×