Updated date:

How to Pass Data From UITableView to Detail View Controller

Kevin is a Software Developer with 20 years experience designing and building business intelligence and system integration solutions.


This tutorial will show you how to display detailed information in the iOS Detail View Controller by selecting an item in the UITableView. This tutorial will display a list of items in UITableView and when you select the item, the description and picture of the corresponding object will display in the Detail View Controller.

For this tutorial, I will use a NSMutableArray that will be populated with data from Wikipedia because their license and copyright allows users to copy content. Of course, you could use SQLite data to populate the array or Core Data for that matter.

Here are the steps:


  • We will create a Data Model to represent the data.
  • We will also create a DAO class to build the data source.
  • Next we will add an UITableViewController on corresponding controller class.
  • We will set this UITableViewController to load first when the app is launched.
  • The view controller that was created when the project is created will contain a UITextView for the item description and an UIImageView for the item’s picture.
  • The UITableViewController will be linked to a UINavigationController and the two view controllers will be connected with a Push segue.

Let's get started.

Create the Project & SampleData NSObject Subclass

  • Create a Single View Application project.
  • When the project is created, add a new NSObject subclass called SampleData (Figure 1).
  • In the header file, add three instance variables to represent our data which will be trees. See listing 1.

Listing 1 - SampleData.h

#import <Foundation/Foundation.h>

@interface SampleData : NSObject

@property(nonatomic,strong) NSString * treeName;
@property(nonatomic,strong) NSString * treeDescription;
@property(nonatomic,strong) UIImage * treePicture;


Now you should open the implementation file and synthesize the three variables as in listing 2.

Listing 2 - SampleData.m

#import "SampleData.h"

@implementation SampleData
@synthesize treeName, treePicture, treeDescription;


Add the SampleDataDAO Subclass

  • The next step is to create the SampleDataDAO class to implement the SampleData object and load the data in the data source. Create a new NSObject and call the subclass, SampleDataDAO.
  • Open the the header file and define a NSMutableArray for our data source as in listing 3.
  • Also import the SampleData class.

Listing 3 - SampleDataDAO.h

#import <Foundation/Foundation.h>
#import "SampleData.h"

@interface SampleDataDAO : NSObject

@property(nonatomic, strong) NSMutableArray * someDataArray;

-(NSMutableArray *)PopulateDataSource;

  • Likewise we will build the data source for our UITableView and Detail View using the data in SampleDataDAO class. See listing 4.
  • In the body of the PopulateDataSource method initialize the someDataArray variable that we have synthesized.
  • Then create a SampleData object to represent our data.
  • Assign the values for each entry as listed below. If you want to use other data, you are more than welcome as long as you follow the same pattern.
  • The picture files are from Wikipedia or you can your own but they are stored in the Resource folder of the app.
  • Add the SampleData (mydata) object to the array and reset the mydata object.
  • Return the someSampleArray since the PopulateDataSource method has a NSMutableArray return type.

Listing 4 - SampleDataDAO.m

#import "SampleDataDAO.h"

@implementation SampleDataDAO

@synthesize someDataArray;

-(NSMutableArray *)PopulateDataSource
    someDataArray = [[NSMutableArray alloc] initWithCapacity:3];
    SampleData * mydata = [[SampleData alloc] init];
    mydata.treeName = @"Oak";
    mydata.treeDescription = @"An oak is a tree or shrub oak tree, of which about 600 species exist. The Oak is native to the northern hemisphere, and includes deciduous and evergreen species extending from cool temperate to tropical latitudes in Asia and the Americas.";
    NSString * file = [[NSBundle mainBundle] pathForResource:@"oak" ofType:@"jpg"];
    mydata.treePicture = [UIImage imageWithContentsOfFile:file];  
    [someDataArray addObject:mydata];
    mydata = nil;
    mydata = [[SampleData alloc] init];
    mydata.treeName = @"Douglas Fir";
    mydata.treeDescription = @"Douglas-firs are medium-size to extremely large evergreen trees, 20â120 metres (70â390 ft) tall (although only Coast Douglas-firs reach such great height). The leaves are flat, soft, linear. They completely encircle the branches, which can be useful in recognizing the species. The female cones are pendulous, with persistent scales (unlike true firs), and are distinctive in having a long tridentine (three-pointed) bract that protrudes prominently above each scale (it resembles the back half of a mouse, with two feet and a tail).";
    file = [[NSBundle mainBundle] pathForResource:@"DouglasFir" ofType:@"jpg"];
    mydata.treePicture = [UIImage imageWithContentsOfFile:file];  
    [someDataArray addObject:mydata];
    mydata = nil;
    mydata = [[SampleData alloc] init];
    mydata.treeName = @"Sugar Maple";
    mydata.treeDescription = @"Sugar Maple is a species of maple native to the hardwood forests of northeastern North America, from Nova Scotia west to southern Ontario, and south to Georgia and Texas.Sugar maple is best known for its bright fall foliage and for being the primary source of maple syrup.";
    file = [[NSBundle mainBundle] pathForResource:@"SugarMaple" ofType:@"jpg"];
    mydata.treePicture = [UIImage imageWithContentsOfFile:file];  
    [someDataArray addObject:mydata];
    mydata = nil;
    return someDataArray;

Build UITableViewController

  • The next steps will build the UITableView in the storyboard and the view controller custom class.
  • Open the storyboard and add a new UITableViewController to the canvas from the Object Library.
  • With the UITableViewController selected, right click on the Cell Prototype and drag a connection to the DetailViewController (klViewController). Select the Push segue when you release the mouse button (Figure 2).
  • With the Cell Prototype selected, open the Attributes inspector and name the Cell in the Identifier field (Figure 3).
  • Once the segue is created, select it and open the Attributes inspector and enter the “treeCell” identifier in the Identifier field (Figure 4). We will need the segue name later.
  • One more step for the UITableViewController, select it and select: Editor->Embed In->Navigation Controller (Figure 5) to create a Navigation Controller and connect it to the UITableViewController. Notice how the Navigation Controller is automatically set to “Is Initial View Controller”.
  • You will need to configure the delegate and data source next. Right click on UITableView and drag a connection to the object proxy (yellow globe) at the bottom of view controller. Select delegate in the popover. Repeat the same process for the data source. Figure 6.
  • Create a new custom class as a subclass of the UITableViewController and name it klListViewController. Add the class to the UITableViewController in the Storyboard by selected the UITableViewController and adding the klListViewController by opening the Identity inspector (Figure 7) and adding it to the Custom Class field.
  • In the header file, klListViewController.h add import statements for the SampleDataDAO, SampleData and the klViewController.
  • Add a instance variable for the SampleDataDAO class, daoDS and add a instance variable for the NSMutableArray ds. See listing 5.

Listing 5 - klListViewController.h

#import <UIKit/UIKit.h>
#import "SampleDataDAO.h"
#import "SampleData.h"
#import "klViewController.h"

@interface klListViewController : UITableViewController

@property(nonatomic, strong) SampleDataDAO *daoDS;
@property(nonatomic, strong) NSMutableArray *ds;

  • In the implementation file after synthesizing the variables initialize the daoDS object and assign the data from the PopulateDataSource to the self.DS object as in listing 6.

Listing 6 - viewDidLoad method

- (void)viewDidLoad
    [super viewDidLoad];
    daoDS = [[SampleDataDAO alloc] init];
    self.ds = daoDS.PopulateDataSource;

  • Next we will need to configure the UITableView, so in the numberOfSectionsInTableView method set the number of sections to 1 to only display the first item in the array, the treeName. Listing 7.

Listing 7 - numberOfSectionsInTableView method

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

    // Return the number of sections.
    return 1;
  • The next method that must be configured is the numberOfRowsInSection. This indicates the length of the items to be displayed in the table. You could use the count property of the array to specify the elements to return, but for this example, I will simply specify 3. See listing 8 below.

Listing 8 - numberOfRowsInSection

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    // Return the number of rows in the section.
    return 3;
  • The last method that we need to configure is the cellForRowAtIndexPath method to add the data source to the cells. You will need to change the value of the CellIdentifier to the name that was defined in the Cell Prototype in the Storyboard. The rest of the code is boilerplate and it is included when you create a custom UITableViewController. What you need to add is the code to add assign the values to the Cells. Define a new SampleData object and assign it the object from the array for each row number. The method will call each item in the ds array automatically. You don’t need to loop. Assign the value of the treeName to the cell.textLabel.text property to display the value in the table. The NSLog is for debugging purposes. See listing 9 for the complete implementation of the method.

Listing 9 - cellForRowAtIndexPath Method Implementation

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    static NSString *CellIdentifier = @"treeCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    SampleData * sample = [self.ds objectAtIndex:indexPath.row];
    cell.textLabel.text = sample.treeName;
    NSLog(@"Cell Value %d %@",indexPath.row,  cell.textLabel.text);
    return cell;
  • Up until now all the work was to populate the data source display the data in the table. To send data to the Detail View Controller when a cell is selected, we will need to add the prepareForSegue method.
  • The first part is to check to see if the calling segue is the segue we have defined between the two view controllers. You could use the exact same technique is you had several segues.
  • Then create a new klViewController object and assign it as the destinationViewController of the calling segue. Once the detailViewController is created assign the value of selected cell from the ds data source, which contains a listing of SampleData objects, to the treeData SampleData object on the DetailViewController as in listing 10. To complete the implementation, will will derefence, so to speak, the object in the klvViewController viewwillAppear method.

Listing 10 - The prepareForSegue Method Implementation

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        klViewController *detailViewController = [segue destinationViewController];
        detailViewController.treeData = [self.ds objectAtIndex:[self.tableView indexPathForSelectedRow].row];

Develop the klViewController Class

  • Start by opening the storyboard again and add a UITextField and an UIImageView to the view controller that was created with the initial project.
  • Next create IBOutlets for both by control dragging connections to the header file and naming them treeInfo and treePicture.
  • Next open the header file and add the @class directive for the SampleData class.
  • Also import the SampleData header.
  • Next define a SampleData instance variable, treeData. This is contain the SampleData information that will be selected in the klListViewController. See listing 11.

Listing 11 - The klViewController.h File

#import <UIKit/UIKit.h>
#import "SampleData.h"

@class SampleData;
@interface klViewController : UIViewController

@property (strong, nonatomic) IBOutlet UITextView *treeInfo;
@property (strong, nonatomic) IBOutlet UIImageView *treePicture;
@property (nonatomic, strong) SampleData * treeData;

  • Finally in the implementation file, add code to the viewWillAppear method , listing 12, to assign the referenced SampleData object, treeData, to the local instance of the object. Then assign the values of the treeDescription to the UITextView: treeInfo. Likewise do the same for the image by assigning the value of treePicture to the UIImageView of the same name.

Listing 12 - viewWillAppear Method

- (void)viewWillAppear:(BOOL)animated
    [super viewWillAppear:animated];
   // treeData = [[SampleData alloc] init];
    treeData = (SampleData *)self.treeData;
    self.treeInfo.text = treeData.treeDescription;
    self.treePicture.image = treeData.treePicture;

Listing 13 - The klViewController.m Implementation File

#import "klViewController.h"

@implementation klViewController
@synthesize treeInfo;
@synthesize treePicture;
@synthesize treeData;

- (void)didReceiveMemoryWarning
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.

#pragma mark - View lifecycle

- (void)viewDidLoad
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.

- (void)viewDidUnload
    [self setTreeInfo:nil];
    [self setTreePicture:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;

- (void)viewWillAppear:(BOOL)animated
    [super viewWillAppear:animated];
   // treeData = [[SampleData alloc] init];
    treeData = (SampleData *)self.treeData;
    self.treeInfo.text = treeData.treeDescription;
    self.treePicture.image = treeData.treePicture;

- (void)viewDidAppear:(BOOL)animated
    [super viewDidAppear:animated];

- (void)viewWillDisappear:(BOOL)animated
	[super viewWillDisappear:animated];

- (void)viewDidDisappear:(BOOL)animated
	[super viewDidDisappear:animated];

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);


The Output

Here is a couple of screenshots of the items in the UITableView and the data on display in the DetailViewController. Figure 8 and 9.

Figure 8 - The List of Items

Figure 8 - The List of Items

Figure 9 - The Details

Figure 9 - The Details

This article is accurate and true to the best of the author’s knowledge. Content is for informational or entertainment purposes only and does not substitute for personal counsel or professional advice in business, financial, legal, or technical matters.


Kevin Languedoc (author) from Canada on April 20, 2014:

check out www.iodev101.com under downloads

Noel on January 22, 2014:

Hi Kevin,

Could you email me the code for this project as I thought I followed it properly but app seems to crash when I press on a tableview cell?

My email is noelgillen21@gmail.com - thanks!

Kevin Languedoc (author) from Canada on January 17, 2014:

Hi Matt

I have other tutorials on Core Data that you can use and combine with this tutorial. Hope this helps.

I will be getting back to writing soon as my other big projects are winding down.

matt on January 14, 2014:

Hello, I was wondering if you either had a tutorial or show me how to implement this with core data?

Kevin Languedoc (author) from Canada on August 31, 2013:


the file is upload and the download links are working. I recently moved to a new hosting and CMS. The links weren't operational on the new web site. Now they are.

Kevin Languedoc (author) from Canada on August 31, 2013:


I am sorry but the project that you needed was not indeed there. It is called TableViewAndDetailExample. I am uploading to the iosdev101.com web site right now.

Kevin Languedoc (author) from Canada on August 29, 2013:

it is the DBTUITableView v2.zip app

David on August 23, 2013:

Still looking for code on this tutorial. I don't seem to be finding it at www.iosdev101.com

Kevin Languedoc (author) from Canada on July 31, 2013:

please see sample projects at www.iosdev101.com

marco on July 31, 2013:


Could you post the code of this project? I have these issues:

- klViewDetail is a subclass of UIViewController?

- when i try to write the viewDidLoad method i receive an error that told me that daoDS does not exist;

- Where i have to write the preparetosegue method?

thx a lot


JFS on June 18, 2013:

Hello klanuedoc. Very good tutorial. I'm a beginner but didn't struggle at all with your help. I could use your suggestions straight within my code and understood everything easily. Thank you very much!

Kevin Languedoc (author) from Canada on May 13, 2013:

Hi thanks

check out my web site at www.iosdev101.com/downloads

Lage Lind on April 30, 2013:

Hi! Awesome tutorial, however, i can't get it to work. Nothing loads in the detailView.. could i have the project? the iosdev102l link isn't working. My email is laymachine@gmail.com

Thanks in advance!

Kevin Languedoc (author) from Canada on March 19, 2013:

check out the source code at www.iosdev102.com/downloads. Also what is the details of the sigart error

LAOMUSIC ARTS on March 15, 2013:

Thanks for the tut but it´s very confusing about the user interface.I am getting a SIGART error.

May you send me the demo-project so I can compare both versions ?



Kevin Languedoc (author) from Canada on January 15, 2013:

Hi Suzana,

Check out (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section for section titles or set the title on the viewcontroller:

viewController.title = cell.textLabel.text;

Suzana on January 15, 2013:

Hi Kevin,

Can you put the data in label instant of title in UITableView?

Kevin Languedoc (author) from Canada on January 08, 2013:

hi Adrian,

As a matter of fact I did. Here is the link to it:


Adrian on January 07, 2013:

Hi Kevin,

Did ever get the chance to publish the search tutorial?

Kevin Languedoc (author) from Canada on January 02, 2013:

Hey Adrian,

Sorry for the tardiness....

Merry Christmas and a Happy New Year to you and your family and friends. I wish you all the best for 2013. I am glad that my tutorials are helping.

Adrian on December 31, 2012:

Hi Kevin

Happy new year man. Thanks for letting me know about the tutorial. I will check your site everyday for it.



Adrian on December 24, 2012:

Merry Christmas Kevin. I just wanted to let you know that your work is teaching me a lot and I appreciate it. So keep up the good work and merry Christmas to you and your loved ones from Atlanta ga USA.


Kevin Languedoc (author) from Canada on December 22, 2012:

The tutorial is nearly finished I will post a link here when I publish later today if possible.

Adrian on December 21, 2012:

Thank you for your interest in my inquiry. Please let me know when you post the tutorial.

Much appreciated


Kevin Languedoc (author) from Canada on December 15, 2012:

wow dwreves I didn't notice that until now and I go over my work before publishing...weird.

if you look at a UIViewController in the Storyboard there is a yellow circle icon on the bottom panel of the UIViewController. When you drag a connection to this icon a popover appears when you release the mouse button.

I will add figures 6 & 7.

Most likely you missed a step. Have you set breakpoints in the code of the second view controller to see if the objects get initialized.

Dale from Netherlands on December 15, 2012:


Thanks for the work you put forth on these tutorials. I just went through this one and I have an issue with building the UITableViewController. Where's figure 6 and 7? I was at the step "to configure the delegate and data source next. Right click on UITableView and drag a connection to the object proxy (yellow globe) at the bottom of view controller. Select delegate in the popover. Repeat the same process for the data source. Figure 6". I don't understand what you mean by the yellow globe at the bottom. When I right click on TableView it shows those two connections are already made. I made my attempt at it and went forward to the end of the tutorial and it builds successfully. When it runs in the simulator, the second view doesn't display the image or tree data.

What should I do next?



Kevin Languedoc (author) from Canada on December 11, 2012:

hi Adrian

I am working on it....

Adrian on December 09, 2012:

Thank you so much. Please let me know when you get around it and where can I see the new tutorial.

Thanks again


Kevin Languedoc (author) from Canada on December 08, 2012:

nice idea. I can do that for you.

Adrian on December 04, 2012:

I saw the tut. Pretty nifty work man. I just couldn't figure out the predicate since there was only one reference to it. So I guess I'm requesting a sub tutorial if possible on how to add search to this tut if you ever get a chance.



Kevin Languedoc (author) from Canada on December 04, 2012:

Search is fairly easy. You need to use NSPredicate and filter the data source of the table, not the table itself since the table is only there to display the contents of the data source. You can apply a filter using NSPredicate and its filtering methods to filter an NSArray or NSMutableArray. Have a look at this tutorial that uses NSPredicate to filter


check out the viewDidLoad method in the Master View Controller for an example.

amp on December 03, 2012:

is there a way you can help with adding search to this tableview. ? it will be truly helpful.


Kevin Languedoc (author) from Canada on October 05, 2012:

Change self.tableView to the name of the tableview object (IBOutlet?) that you created. You will also probably need to set the delegate and datasource in the proxy (in the storyboard). Hope this helps Will....


You're very welcome.

Will on October 05, 2012:

I am trying to change It from a TableViewContoller to a tableView.

What would I change tableView to in this line of code?

detailViewController.treeData = [self.ds objectAtIndex:[self.tableView indexPathForSelectedRow].row];

Will on October 05, 2012:

Thanks Very helpful.

Vetranks from Shinjuku-ku, Tokyo, Japan on October 02, 2012:

thanks so much Kevin

Kevin Languedoc (author) from Canada on September 30, 2012:

Sure no problem Stefano. I am glad to help out.

Vetranks from Shinjuku-ku, Tokyo, Japan on September 29, 2012:

Sorry Kevin my t9 telephon don't go very well

Vetranks from Shinjuku-ku, Tokyo, Japan on September 29, 2012:

Hi levino, can i nave the code please? my mail is Stefano.dicati@gmail.com

Kevin Languedoc (author) from Canada on August 17, 2012:

To load html, you will a need UIWebView on the scene and then set the url parameter to the url to the html file, either on the web or in the Resource folder. Make sure to add a delegate of the WebView to the Proxy icon at the bottom of the scene where the Webview is located. You can also code html directly into the webview but I find it easier to load a file unless you have to add some dynamic information to the html from variables. To load a html as a string, take a look at loadHTMLString:htmlString method in the UIWebView class.

Let me know how it works out for you.

Keith from Alberta, Canada on August 16, 2012:

Hi Kevin,

This tutorial helped me understand prepareforseque and how to load more than one set of images in an NSArray. I have gone through many tutorials and I just didn't understand it so Thank-You.

I would like to load the description as an html file to use the "Justify" text formating that iOS lacks at this moment. Would you get the html into the array or just get the path of the html file into the array and how is this done.


Kevin Languedoc (author) from Canada on July 27, 2012:


piyushpatil85 from Pune on July 27, 2012:

good for beginners

Kevin Languedoc (author) from Canada on June 19, 2012:

That is a good question :). You could convert the app to Core Data and then use a predicate to query the Core Data storage facility (SQLite). You could also implement a NSPredicate filter to filter the content of the array that is used as the data source. I have an example here in this tutorial


Have a look in the viewDidLoad method in the MasterViewController implementation file.

amp76 on June 15, 2012:

hi kevin,

thanks for a quick and clean tut. very helpful. i have 1 question. how to you go about adding a search bar that searches the tableview?



Kevin Languedoc (author) from Canada on May 31, 2012:

Sure, you can send to kevinlanguedoc@gmail.com


DOMO on May 30, 2012:

Would it be possible for me to email you my project file so you can have a better understanding of my storyboard and code. I'm a newbie to xcode and may have made some should-not-do mistake

Kevin Languedoc (author) from Canada on May 30, 2012:


Did you add your segue correctly. Also did you create the navigation controller correctly?

CravenPD on May 30, 2012:

I don't know what i did wrong, but if i click on a cell, nothing happened.

donno what i did wrong.

anybody any idea?

Kevin Languedoc (author) from Canada on May 30, 2012:


You can remove the dataobj variable since the current example doesn't need it. I used it for an earlier version. Sorry about that. As for the prepareForSegue, this is working fine as is. I don't know where or why you are getting a reference to a NSString because the identifier is a NSString object and if you look at the NSString class, the isEqualToString, is there and supported.


DOMO on May 30, 2012:

just a few question... under listing 13, what is dataobj?

and the prepare for segue method, there is a error which says "no visible @interface for NSString declare the selector isEqualToString?

it is a very nice tutorial but there seem to be many empty spots which seem to confuse user/learner

Kevin Languedoc (author) from Canada on April 21, 2012:


As promised, here the tutorial to display SQLite data in a UITableView and DetailView Controller:


Bettina on April 20, 2012:

Hi Kevin,

this sounds very good.

Then, I hope to tomorrow ...

Good night from Germany

Kevin Languedoc (author) from Canada on April 20, 2012:

The code is done except data not saving properly to database

Bettina on April 20, 2012:

Hi Kevin,

okay, I will wait ...

Hope to hear from you soon ;-)

Kevin Languedoc (author) from Canada on April 19, 2012:

Hi Bettina,

I have a couple of issues with code to work out and I need to finish writing the instructions, so it will be another day before complete. Sorry!

Kevin Languedoc (author) from Canada on April 19, 2012:

My book should be published during the month of August or September 2012. I will a link to the tutorial in these comments later

Bettina on April 19, 2012:

Okay, very nice. I am excited :-)

I've read that you write a book. When will it be released?

Now it is time to sleep and dream of Xcode ;-)

Kevin Languedoc (author) from Canada on April 19, 2012:

I should be able to post the tutorial later today (EST). It is amazing how time flies by when we are struggling with code.

Bettina on April 18, 2012:

Oh, that would be fantastic!!!

I'm still trying to solve my problem ... 12 hours today, but unfortunately without success.

I do not know what I'm doing wrong ...

I'd be so happy if I can do it.

Thank you for your effort ... I'm looking forward to your message!

Kevin Languedoc (author) from Canada on April 18, 2012:

I will supply the code...hang on ;)

Bettina on April 18, 2012:

Hi Kevin,

I'm so unhappy. I'm sitting here for hours, but it doesn't work.

I will be the happiest girl in the world, if you can do this tutorial with a sqlite database!!!!

Or perhaps you know where I find such a tutorial using storyboard.

Thanks Betti

Bettina on April 18, 2012:

Hi Kevin,

I was on vacation for a few days to visit a girlfriend.

Now I'm back and am very pleased that you have sent a reply to me.

I'll try to follow your advice. I hope that it works ...

Sincere thanks to you, that you took the time to answer me.

I give you notice, if it works.

See you soon

Kevin Languedoc (author) from Canada on April 13, 2012:

Hi Bettina,

I am more than happy to help out if and when I can. Basically,

1- Define a class to represent your data, like I did with SampleData.

2- In the the PopulateDataSource, create a instance of your custom data class

3- Create an instance of a NMUtablearray, like in the tutorial

NSMutableArray *sampleArray= [[NSMutableArray alloc] initWithCapacity:aInteger];

aInteger is an int and is the maximum amount of items in your array

you can use NSMutableArray *sampleArray= [[NSMutableArray alloc] init];

instead if you don't know how many items will be in the array

3- open your database and create your prepared statement

@try {

NSFileManager *fileMgr = [NSFileManager defaultManager];

NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"IOSDB.sqlite"];

BOOL success = [fileMgr fileExistsAtPath:dbPath];



if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))


NSLog(@"An error has occurred.");


const char *sql = "SELECT id, Wine, Rating, Photo FROM WineTbl";

sqlite3_stmt *sqlStatement;

if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)


NSLog(@"Problem with prepare statement");


4- Read from the database

while (sqlite3_step(sqlStatement)==SQLITE_ROW) {

YourDataObject *myClass= [[YourDataObject alloc]init];

myClass.wineId = sqlite3_column_int(sqlStatement, 0);

myClass.wine = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];

myClass.rating = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 2)];

const char *raw = sqlite3_column_blob(sqlStatement, 3);

int rawLen = sqlite3_column_bytes(sqlStatement, 3);

NSData *data = [NSData dataWithBytes:raw length:rawLen];

myClass.photo = [[UIImage alloc] initWithData:data];

[sampleArray addObject:myClass];

myClass = nil;



@catch (NSException *exception) {

NSLog(@"An exception occurred: %@", [exception reason]);



return sampleArray ;


5- Add your array of SQLite data to the TableView Data Source

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


static NSString *CellIdentifier = @"myCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];


YourDataObject * sample = [self.PopulateDataSource objectAtIndex:indexPath.row];

cell.textLabel.text = sample.propertyValueFromYourClass;

NSLog(@"Cell Value %d %@",indexPath.row, cell.textLabel.text);

return cell;


6- To send data to the other view controller just follow the rest of this tutorial.

hope this helps


Bettina on April 12, 2012:

Hi Kevin,

I made this tutorial and "iOS 5 How To SQLite Data display in a UITableView." Both tutorials are great and I have a lot of fun. Unfortunately, I do not understand how I can apply this to the previous tutorial. I like to load the data from the sqlite db instead of wikipedia. Through a tip I would be very happy. I am a beginner from Germany and I have unfortunately no one here can I ask the ... I hope you understand what I mean. In any case, thanks for the tutorials so far. Greetings Bettina

Kevin Languedoc (author) from Canada on April 11, 2012:

Thanks Jakub, I am really glad everything is working for you. You certainly can contact me if you need help. If I can i will do my best to guide you in the right direction. BTW, one of my friends is almost a neighbor to you. He used to live in Slovakia.

Jakub on April 11, 2012:

I get it! I have to admit, I was surprised when I pushed the build and run button and that worked...:-) great!

Thanks for your help again!

Would you mind, if I contact you again, when I have some problem or question about programming...? I don't know anyone in my place I live in to ask for a question.

Sorry for my English...I am from Czech Republic by the way...I LOVE internet!

Kevin Languedoc (author) from Canada on April 11, 2012:

Exactly, just use the same technique but use the code form the other tutorial to build your NSMutableArray. Once the array is built proceed with the info from this tutorial.

Jakub on April 11, 2012:

Hi klanguedoc,

Before I start writing this tutorial, I have the question...To populate the MutableArray with data from SQLite(not from wikipedia) I will be doing the same way as implementation the dataList NSMutableArray in the previous tutorial? Thanks!