report

How-To Pass Data from UITableView to Detail View Controller

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:

Outline

  • 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


Lets 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;


@end

Next 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;

@end

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;

@end
  • 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 ar emore 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;
} 
@end

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.

Figure 2 - Configure the Push Segue
Figure 2 - Configure the Push Segue
Figure 3 - Create UINavigatorViewController
Figure 3 - Create UINavigatorViewController
Figure 4 - Set is Initial View Controller
Figure 4 - Set is Initial View Controller
Figure 5 - Configure Cell Identifier
Figure 5 - Configure Cell Identifier

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;


@end
  • 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;

@end
  • 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);
}

@end

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

More by this Author


Comments 69 comments

Jakub 4 years ago

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!


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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 4 years ago

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!


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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.


Bettina 4 years ago

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


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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(success)

{

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;

}

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

Kevin


Bettina 4 years ago

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


Bettina 4 years ago

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


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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


Bettina 4 years ago

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!


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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 4 years ago

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 ;-)


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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!


Bettina 4 years ago

Hi Kevin,

okay, I will wait ...

Hope to hear from you soon ;-)


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

The code is done except data not saving properly to database


Bettina 4 years ago

Hi Kevin,

this sounds very good.

Then, I hope to tomorrow ...

Good night from Germany


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

Bettina

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

http://hubpages.com/technology/iOS-5-How-To-Displa...


DOMO 4 years ago

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


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

Hi

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.

Kevin


CravenPD 4 years ago

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?


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

Hi

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


DOMO 4 years ago

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


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

Sure, you can send to kevinlanguedoc@gmail.com

K


amp76 4 years ago

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?

thanks

adrian


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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

https://turbofuture.com/misc/Core-Data-How-To-Stor...

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


piyushpatil85 profile image

piyushpatil85 4 years ago from Pune

good for beginners


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

Thanks


keithatbbpp 4 years ago from Alberta, Canada

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.

Keith


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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.


Vetranks profile image

Vetranks 4 years ago from Shinjuku-ku, Tokyo, Japan

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


Vetranks profile image

Vetranks 4 years ago from Shinjuku-ku, Tokyo, Japan

Sorry Kevin my t9 telephon don't go very well


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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


Vetranks profile image

Vetranks 4 years ago from Shinjuku-ku, Tokyo, Japan

thanks so much Kevin


Will 4 years ago

Thanks Very helpful.


Will 4 years ago

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];


klanguedoc profile image

klanguedoc 4 years ago from Canada Author

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....

Vetranks

You're very welcome.


amp 4 years ago

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

adrian


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

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

https://turbofuture.com/misc/Core-Data-How-To-Stor...

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


Adrian 3 years ago

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.

Respectfully

Adrian


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

nice idea. I can do that for you.


Adrian 3 years ago

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

Thanks again

Adrian


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

hi Adrian

I am working on it....


dwreves profile image

dwreves 3 years ago from Netherlands

Kevin,

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?

Thanks.

Dale


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

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.


Adrian 3 years ago

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

Much appreciated

Adrian


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

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


Adrian 3 years ago

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.

Adrain


Adrian 3 years ago

Hi Kevin

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

Regards

Adrian


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

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 3 years ago

Hi Kevin,

Did ever get the chance to publish the search tutorial?


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

hi Adrian,

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

http://hubpages.com/technology/Develop-a-UISearchB...


Suzana 3 years ago

Hi Kevin,

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


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

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;


LAOMUSIC ARTS 3 years ago

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 ?

LAOMUSIC@hotmail.com

tHANKS FOR ANY HELP 1


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

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


Lage Lind 3 years ago

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!


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

Hi thanks

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


JFS 3 years ago

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!


marco 3 years ago

Hi,

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

Regards


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

please see sample projects at www.iosdev101.com


David 3 years ago

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


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

it is the DBTUITableView v2.zip app


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

David,

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.


klanguedoc profile image

klanguedoc 3 years ago from Canada Author

David,

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.


matt 2 years ago

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


klanguedoc profile image

klanguedoc 2 years ago from Canada Author

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.


Noel 2 years ago

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!


klanguedoc profile image

klanguedoc 2 years ago from Canada Author

check out www.iodev101.com under downloads

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article

    Menu

    Explore