iPhone Programming Tutorial – Populating UITableView With An NSArray

August 8th, 2008 Posted by: brandontreb - posted under:Tutorials

The goal of this tutorial is to show you how to populate a UITableView with data from an array of objects. This will be the building block to display XML data as well as SQL data.

The theme of this application will be fruit. We will create an array of “fruit” objects that have some additional information besides the name. We will populate a UITableView with the names of the fruits. When the user selects a fruit from the list, the view will transition to another one and display specific details about that fruit.

I will try to be as detailed as possible however it would be useful if you have completed the following tutorials as I will use concepts from each of them:

In this tutorial you will learn:

Open up X-Code and Select File->New Project… Select Navigation-Based Application and click Choose…
Name your project Fruit.

We are going to create our “fruit” objects that will be used in the application. If you are not too familiar with object oriented programming…. That tutorial would be a little too huge for me to write.

Click on File -> New File… The object we are creating will inherit from NSObject, so select NSObject Subclass and click Next.

The next screen will ask you to name it. Go ahead and name it “Fruit” and make sure that “Also create Fruit.h” is checked. It should look like the screen below. Then, click Finish.

Now, we are going to define the properties of a “Fruit” object. For this application a fruit will have a name and a description. Open Fruit.h and add the following code:

We have created the properties needed to represent our fruit. There is one line that you may be unfamiliar with. The line -(id)initWithName:(NSString*)n description:(NSString *)desc; is a definition for a function. This function will be called to initialize a Fruit object. All NSObjects have an init method, but we want to create our own so that we can pass in a name and description when the object is created.

Open up Fruit.m and add the following code:

Here we implement the initWithName method. The code here seems pretty straight forward. We are basically setting our local copies of name and description to the arguments passed to this method. The important thing to notice here is the return self line. This is crucial for using this method as a constructor. It allows this function to return the newly created instance of a fruit object.

Next, we are going to set the title of our main view. This is necessary to create a back button when transitioning between views. Open up RootViewController.m…In the viewDidLoad method, add the following code:

We are setting the title property of the RootViewController object to the string “Fruits”. Also, be sure to add the #import “Fruit.h” line at the top to include the fruit object in our project as well as @synthesize fruitView to add the “getter” and “setter” methods.

Next, we are going to create an array of fruit objects. Open up FruitAppDelegate.h and add the following code:

All we are really adding here is an NSMutableArray property. I used NSMutableArray instead of NSArray because it has a few more methods making it more flexible.

Now, open up FruitAppDelegate.m and add @synthesize fruits to the top. This is so other objects will have access to the fruits array. Also, be sure to include the import statement for Fruit.h.

Now add the following code to the applicationDidFinishLaunching method.

What we are doing here in the 1st three lines is creating new instances of a fruit object. Notice that instead of calling init, we are calling the initWithName method that we created. This is allowing us to pass in a name and a description to each of the fruits.

The next line [self.fruits = [[NSMutableArray alloc] initWithObjects:apple,orange,watermelon,nil]; builds a new array from the objects we just created. It is important to pass in nil as the last argument in an NSMutableArray. It will not work unless you remember this.

Now we are going to create the view that will be displayed when the user selects a fruit. Double click on any one of your .xib files to open up Interface Builder.

Click File -> New and select view and click choose.

You should now see the new view (it will be blank) and the objects associated with it. We need some sort of text field to display the description of the fruit. For this tutorial I have chosen a UITextView as opposed to a UITextField. This is because a UITextView is multi-line and is great for displaying more than one line of text. So, go ahead and drag it on to your view. Your view window should now look like this:

Now click File -> Save. One important thing to keep in mind is to make sure you are saving it in the current project’s directory. It seems that every time I add a view to a project, the default directory is not my project’s directory. Name this file FruitViewController and click Save.

Another window should show up after you click save. It is asking you if you want to add this view to your project. Just check the box net to Fruit ,click Add, and close Interface Builder.

Close Interface Builder and go back to X-Code.

We need to create a ViewController to handle our View. Click File -> New File… Select UIViewController subclass and click Next.

Name this file FruitViewController.m and check the box that says “Also create “FruitViewController.h” . Click Finish.

Now we will declare an Interface Builder Outlet for the UITextView that we added to the view. Open up FruitViewController.h and add the following code.

This line allows us to associate the fruitDescription property with the UITextView we created. Open up FruitViewController.m and add this code underneath @implementation keyword. This creates default “getter” and “setter” methods for the fruitDescription property.

Double click on FruitViewController.xib to open it in interface builder. We need to connect the view to the FruitViewController class we just created. Click on the File’s Owner object.

Click Tools -> Identity Inspector. Select FruitViewController from the dropdown next to class. Notice that under the Class Outlets section you will see the UITextView property we created.

The last step in interface builder is to connect the UITextView. Click Tools -> Connection Inspector. You should see an Outlet that says fruitDescription. Click in the corresponding circle and drag it over the UITextView on your view and release it.

Now, click the circle next the word View under outlets and drag it to the View object inside of the window that says FruitViewController in the title. When you are done the screen should look like this:

Now close Interface Builder.

The first thing we are going to do here is create a property for our new view so that it can be transitioned to when a fruit gets clicked on. Open RootViewController.h and add the following code:

We are just creating a property for the fruitViewController that we added to the project. Also note that I added the #import “FruitViewController.h” line. this will allow us to create new instances of the FruitViewController object.

Now open the RootViewController.m and find the numberOfRowsInSection method. This method tells the UITableView how many rows it will be displaying. In our case it will be the size of the array of fruits. Add the following code (click the image to enlarge):

The first line allows us to gain access to the appDelegate of our application. This is where we defined the fruit array. Once we have access to the delegate the count property of the fruit gets returned.

Now find the cellForRowAtIndexPath method and add the following code:

So the first line we added is the “FruitAppDelegate *appDelegate…” line. Again, this is giving us access to the appDelegate object where we declared the fruit array. The next line calls the objectAtIndex method on the Array of fruits. The index we will be using can be accessed via indexPath.row. This is an integer value representing each row of the UITableView. Finally, we call the setText method of the cell, to display the name of the fruit in each cell at the given index.


This is the last step. We are going to detect which row in the UITableView the user selected. Find the method called didSelectRow and add the following code(click image to enlarge).

This method gets called every time a user taps on a cell in the UITableView. The parameter indexPath has a property called row that is the integer value of the cell the user clicked on. To access this, we call indexPath.row.

The first line again gives us access to the appDelegate. The next line indexes into the fruits array and makes a copy of the selected fruit object.

The next section starting with “if(self.fruitView == nil)”, initializes the viewController if it hasn’t already been initialized (see my previous tutorial if you need more of an explanation on this). One thing to take note of: Make sure that the parameter you pass to initWithNibName matches the name of the .xib file you used for your view. So in our case, its FruitViewController.

Following this line is the line that pushes the viewController on to the navigationController stack. This causes the view to transition to the new view.

The last 2 lines pass the fruit information to the new view. They are fairly self explanitory. We first set the title of the view to the name of the fruit and then set the description text to the description of the fruit.

Now click Build and Go and your app should launch. Here are some screenshots of how it should look.

And after clicking on a fruit…

Well, I hope that you got a lot out of this tutorial. As always, if you have any questions or comments, feel free to leave them in the comments section of this post. We also have a forum to help you will all of you iphone related questions. If you get lost, you can download the sample code here

Happy iCoding!

  • Sebastien

    another nice Tutorial. I’m very newbie in Iphone Dev and Objective-C. I’ve read the “Objective-C programming” at the apple Dev Center but I need alot of source code to understand so I can’t wait for the next tutorial!

    I have some problems to understand when and how to use “@property” (retain,copy, etc). The next thing i need to practice is the connections in the Interface Builder.

    Thank you for your great tutorials!

  • bobcubsfan

    Great tutorial! Thanks. What I am learning among other things is how picky coding is in regard to punctuation and capitalization. Very easy to make mistakes and generate errors.

  • stowns

    honestly…you’re the shit. I have zero experience with C and had no clue where to start. Your tutorials have seriously sped things up. Thanks for taking the time to spread the knowledge

  • Adam

    Brandon. Thanks for the tutorial.

  • iphoner

    another great one. thankyou. It would be really good to see some tutorials on creating a musical instrument. Apple did have source code for a ‘Kalimba’ instrument on their dev site but this has since been taken down.

  • Phil

    Thanks Brandon, another great tutorial – would it be possible for you to do a tutorial that focuses on the UIScrollView using the mulitouch to zoom in / out images etc?

  • stowns

    one thing i would love to see added to this tutorial is a summary paragraph at the end. Something that sums up how all the files interact upon execution. But only because i’m a nub

  • Leo

    First of all: thanks for this great series of tutorials. They’re very helpful for me!

    One question regarding the “cellForRowAtIndexPath” function in this tutorial:

    FruitAppDelegate *appDelegate = (FruitAppDelegate *)[[UIApplication sharedApplication] delegate];
    Fruit *f = (Fruit *)[appDelegate.fruits objectAtIndex:indexPath.row];
    [cell setText:f.name];
    [f release];

    I understand why you release the “f” object. But I don’t understand why you don’t do the same with the “appDelegate” object. Shouldn’t that object be released from memory as well? Or is it somehow being released in a different way, by a different function? Thanks for any insight you can provide! :-)

  • http://icodeblog.com Brandon

    The reason the appDelegate object does not get released is because we are not building a new instance of it. All we are doing is getting a reference to it. If you release it, you will be releasing your application’s appDelegate.

    I hope that helps.

  • bobcubsfan

    Brandon, I used the tutorial as a model to build an app, and ran into a problem.

    When the array items exceed what the screen can show, and I “scroll” up, the program locks up.

    I extended your array, and got the same results.

    Any ideas?

  • http://icodeblog.com Brandon

    Hrmm… That is odd. I’ll try to mess with it when I get some time. In the mean time, if you figure it out let me know.


  • bobcubsfan

    this is the change I made to your code that causes the problem.

    - (void)applicationDidFinishLaunching:(UIApplication *)application {

    Fruit *apple = [[Fruit alloc] initWithName:@”Apple” description:@”Red Delicious are my favorite”];
    Fruit *orange = [[Fruit alloc] initWithName:@”Orange” description:@”MMM…Fresh squeezed orange juice”];
    Fruit *watermelon = [[Fruit alloc] initWithName:@”Watermelon” description:@”My favorite flavor of Jolly Ranchers”];
    Fruit *apple2 = [[Fruit alloc] initWithName:@”Apple” description:@”Red Delicious are my favorite”];
    Fruit *orange2 = [[Fruit alloc] initWithName:@”Orange” description:@”MMM…Fresh squeezed orange juice”];
    Fruit *watermelon2 = [[Fruit alloc] initWithName:@”Watermelon” description:@”My favorite flavor of Jolly Ranchers”];
    Fruit *apple3 = [[Fruit alloc] initWithName:@”Apple” description:@”Red Delicious are my favorite”];
    Fruit *orange3 = [[Fruit alloc] initWithName:@”Orange” description:@”MMM…Fresh squeezed orange juice”];
    Fruit *watermelon3 = [[Fruit alloc] initWithName:@”Watermelon” description:@”My favorite flavor of Jolly Ranchers”];
    Fruit *apple4 = [[Fruit alloc] initWithName:@”Apple” description:@”Red Delicious are my favorite”];
    Fruit *orange4 = [[Fruit alloc] initWithName:@”Orange” description:@”MMM…Fresh squeezed orange juice”];
    Fruit *watermelon4 = [[Fruit alloc] initWithName:@”Watermelon” description:@”My favorite flavor of Jolly Ranchers”];
    Fruit *apple5 = [[Fruit alloc] initWithName:@”Apple” description:@”Red Delicious are my favorite”];
    Fruit *orange5 = [[Fruit alloc] initWithName:@”Orange” description:@”MMM…Fresh squeezed orange juice”];
    Fruit *watermelon5 = [[Fruit alloc] initWithName:@”Watermelon” description:@”My favorite flavor of Jolly Ranchers”];

    self.fruits = [[NSMutableArray alloc] initWithObjects:apple,orange,watermelon,apple2,orange2,watermelon2,

  • Hanno

    Thx Brandon for that tutorial.

    One question:
    what is the difference in accessing an objects properties or methods via foo.property to [foo property]?

  • BrewersFan

    Brandon thank you for tutorial.

    I am experiencing the same issue bobcubsfan. Both my simulator and hardware lock up when I scroll quickly through list. I don’t have any insight as to why.

    Also does anyone know how to access/convert the fruitDescription as a NSString?


    NSString *str = fruitDescription.text

  • bobcubsfan

    When running on my iPhone, the program quits after scrolling twice without making a selection.

  • bobcubsfan

    This might be a clue:

    The debugger (GDB) was launched when the program bombed.

  • bobcubsfan

    Hey Brewers fan.

    I added NSString *mydesc; to


    @interface RootViewController : UITableViewController {
    FruitViewController *fruitView;
    NSString *mydesc;

    and the second @property …

    @property(nonatomic,retain) FruitViewController *fruitView;
    @property(nonatomic,retain)NSString *mydesc;


    in RootViewController.m after the line in the (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


    [self.fruitView.fruitDescription setText:[fruit description]];

    I added this:
    mydesc =[fruit description];

    no errors, so I guess it works.

  • http://icodeblog.com Brandon

    Hmmm… I’m still working on the issue of the simulator locking up when scrolling. I have compared my code to numerous examples by Apple and can’t seem to see any significant difference.

    Go ahead and post this issue in the forums and see if anyone has a solution.

  • bobcubsfan

    Hey Brewers fan. I forgot this in RootViewController.m

    add the @synthesize mydesc; line.

    @implementation RootViewController
    @synthesize fruitView;
    @synthesize mydesc;

  • BrewersFan

    Thanks bobcubsfan!!! I appreciated you posting NSString code.

    I hope Brandon or message board feedback can resolve the lockup issue.

  • bobcubsfan

    Hey Brewersfan, you are welcome. Did it work for you? I am troubleshooting the lockup problem as well.

  • AstrosFan

    Hi. I was wondering how would I be able to use this tutorial but at the same time, have a tab bar at the bottom. I already made a tab bar application but it doesn’t have the RootViewController or anything. Should I just go ahead and make one? Or is there another way?

  • http://www.itunesregistry.com mainstreetmark

    Hey dude -

    This is exactly the topic and scope I was looking for. I have successfully made a list of stuff.

    I eventually hope to write a native app for itunesregistry.com, but I’ve got nearly no experience in Cocoa, so this will be a learning experience…

  • jonas

    Thank you for excellent articles! Seems like I will have to go brush off some dust from an Objective C book thats lying around here somewhere — your postings really gave me the inspiration for doing so!

    Keep up the great work!

  • daniel

    why in “cellForRowAtIndexPath” method of RootViewController.m need add
    [f release]

    but not need release “fruit” in didSelectRowAtIndexPath

    they also have use the same way (also from fruits NSMutableArray) to get the ref.
    [Fruit *fruit = (Fruit *)[appDelegate.fruits objecctAtIndex:indexPath.row];

  • BrewersFan

    Hey bobcubsfan, I was able to get it to work kinda..

    Basically I’m trying to let the user email the description once they have selected the fruit. I have an email button on FruitViewController.xib.

    Here is my code:


    @interface RootViewController : UITableViewController {
    FruitViewController *fruitView;
    NSString *mydesc;

    @property(nonatomic,retain) FruitViewController *fruitView;
    @property(nonatomic,retain) NSString *mydesc;



    @implementation RootViewController
    @synthesize fruitView;
    @synthesize mydesc;

    [self.navigationController pushViewController:self.fruitView animated:YES];
    self.fruitView.title = [fruit name];
    [self.fruitView.fruitDescription setText:[fruit description]];
    mydesc =[fruit description];


    @interface FruitViewController : UIViewController {
    IBOutlet UITextView *fruitDescription;
    NSString *mydesc;

    @property(nonatomic,retain) IBOutlet UITextView *fruitDescription;
    @property(nonatomic,retain) NSString *mydesc;

    - (IBAction)EmailFruit;



    @implementation FruitViewController
    @synthesize FruitFruitFruitDescription;
    @synthesize mydesc;

    -(IBAction)EmailFruit {

    NSString *str1 =@”mailto:?&subject=Fruit&body=”;
    //NSString *str2 =mydesc;
    NSString *SMessage =[NSString stringWithFormat:@"%@%@",str1,mydesc];

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:SMessage]];


    When I run this the text field of the email should read description however I get (Null).

    Any idea how to fix???

    Thanks again for your HELP…

  • http://icodeblog.com Brandon

    I think I have solved it!

    After reading the post left by daniel, I decided to investigate my choice for releasing the f object.

    After some inspection, I realized that the “f” object wasn’t a new instance of Fruit, but a reference to an existing Fruit object.

    Releasing this object, removes the Fruit at that cell from memory and causes the app to crash.

    So to fix the crashing problem, remove the

    [f release];

    line from cellForRowAtIndexPath method inside of RootViewController.m.

    Thank you to daniel for bringing this to my attention. I will update the tutorial later today.

  • bobcubsfan

    Brandon, you rock! It always seems to be the case that one small thing is the source of a bug!

  • http://icodeblog.com Brandon

    Thanks Bob,

    yea it’s always something dumb that you overlook. So I assume this fixed the bug for you then?

  • bobcubsfan

    Indeed it did. When I was looking at the code, I was kind of wondering about the “f release”, but am still too much of a novice to have nailed it down.

  • BrewersFan

    Hey I got my code to work bobcubsfan. Thanks again for the post. Brandon thanks for the fix.

    This is a GREAT BLOG and you guys have been a big help.

  • BrewersFan

    Does anyone have idea on how to add search bar below list to search array? My list in my app is long and search feature would benefit user.

  • bobcubsfan

    Apple has sample code for a table search with an array. If you want, I can e-mail the dmg to you.

  • bobcubsfan


    Once a value has been passed, how is the value stored for use elsewhere?

    For example, selecting Apple, yields Red Delicious are my favorite in [self.fruitView.fruitDescription setText:[fruit description]];

    So, if I want to use the result, how can I store in and where?

  • bobcubsfan

    Hi Brewersfan,

    What did you do do fix you code?

  • http://icodeblog.com Brandon


    Im not sure I understand your question. Are you asking me how you would store the description of the selected item?

    Let me know so that I can further assist you.

  • bobcubsfan

    I am used to languages that have global variables. For example, declaring a global or public string makes it available everyone, while a private variable is available only in the routine, or method where it is declared. So, maybe I want to capture the description and use it somewhere else, perhaps to just use a substring of it.

    I am thinking that maybe variables declared in the “delegate” and made available by the code in RootViewController

    FruitAppDelegate *appDelegate = (FruitAppDelegate *)[[UIApplication sharedApplication ] delegate];

    would do the job.

  • BrewersFan

    Hey bobcubsfan,

    in the


    I changed:

    mydesc =[fruit description];


    self.fruitView.mydesc =[fruit description];

    This changed (null) to the description…

    Also thank you for the offer to email table search with an array from Apple.

    I have looked at example, specifically 3_SimpleIndexedTableView.

    I would like to add the search functionality to this list however I am just not proficient enough to navigate the code changes..

    I was fishing to see if someone with more proficiency might know how. This way I don’t have to pull all of my hair out…

  • marcus

    Should this compile without warngings? I get warnings in the FruitAppDelegate.m on these lines of code

    Fruit *apple = [[Fruit alloc] initWithName:@”Apple” description:@”My favorite is green”];

    because it says no ‘initwithName:description:’ method found.

    Did I miss a step? I’m import “Fruit.h” into the FruitApp Delegate.m. When I build and go I just get a black screen and it goes into debug mode.

  • http://icodeblog.com Brandon


    If you are getting this warning, it probably means that you did not declare this method inside of your fruit.h.

    - (id) initWithName:(NSString*)n description:(NSString*desc);

    Let me know if that solves your problem. You also may have missed the step where you implement this method inside of fruit.m

  • marcus

    Thanks for the help Brandon. I did declare it in fruit.h. Here is my fruit.h. Notice iniWithName not initWithName. Ooops. It’s working now. Figured it had to be something simple but obscure.


    @interface Fruit : NSObject {
    NSString *name;
    NSString *description;


    @property(nonatomic,copy) NSString *name;
    @property(nonatomic,copy) NSString *description;

    - (id)iniWithName:(NSString *)n description:(NSString *)desc;


  • http://icodeblog.com Brandon

    hehe great to hear you got it working. I hate type-o errors, they take so long to troubleshoot.
    Thanks for being a part of this site!

  • marcus

    Well, I spoke too soon. It comes up fine and displays the fruits but then when I click on a fruit it crashes. It’s crashing on the line:

    self.fruitView.title = [fruit name];

    in the did select a row function.

    Any ideas?

  • http://icodeblog.com/2008/08/19/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-1/ iPhone Programming Tutorial – Creating a ToDo List Using SQLite Part 1 | iCodeBlog

    [...] while still explaining the new stuff in detail.  I will assume that you have completed the fruits tutorial and it’s [...]

  • bobcubsfan


    Try commenting the line with the error.

    //self.fruitView.title = [fruit name];

    See if the error “drifts”.

  • http://icodeblog.com Brandon


    You can open up the error terminal while your application is running. It will give you a detailed log of the error. This should give you some insight as to why your app crashed.

    You can access it by clicking the GDB icon inside of XCode (its located on the middle toolbar and looks like a terminal screen) after clicking Build and Go.

    Paste the error output in the comments so we can see what the problem is.

  • marcus

    Here is the gdb output. Thanks again for your help.

    [Session started at 2008-08-19 16:53:59 -0700.]
    2008-08-19 16:54:02.463 Fruit[4359:20b] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** -[NSCFArray insertObject:atIndex:]: attempt to insert nil’
    2008-08-19 16:54:02.465 Fruit[4359:20b] Stack: (

    [Session started at 2008-08-19 16:54:02 -0700.]
    Loading program into debugger…
    GNU gdb 6.3.50-20050815 (Apple version gdb-960) (Sun May 18 18:38:33 UTC 2008)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type “show copying” to see the conditions.
    There is absolutely no warranty for GDB. Type “show warranty” for details.
    This GDB was configured as “i386-apple-darwin”.warning: Unable to read symbols for “/System/Library/Frameworks/UIKit.framework/UIKit” (file not found).
    warning: Unable to read symbols from “UIKit” (not yet mapped into memory).
    warning: Unable to read symbols for “/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics” (file not found).
    warning: Unable to read symbols from “CoreGraphics” (not yet mapped into memory).
    Program loaded.
    sharedlibrary apply-load-rules all
    Attaching to program: `/Users/not_too_shabby/Library/Application Support/iPhone Simulator/User/Applications/6B90C11F-BA39-4AF0-A7B0-8F8495CE80BE/Fruit.app/Fruit’, process 4359.

  • http://icodeblog.com Brandon

    Hrmm… That is strange. It’s so hard to troubleshoot without seeing your code. I will post up the sample code for this tutorial and you can compare it to yours.

  • BrewersFan

    Hey bobcubsfan, Brandon,

    I am trying to add search feature to array. Specifically I am attempting to add functionality from 3_SimpleIndexedTableView Apple example with side letter search. Basically my code is generating a bunch of errors.

    I ‘m wondering if there is a better approach? Bobcubsfan you mentioned Apple has sample code for a table search with an array. Which the one are you’re referring to?

    At the end of the day I am looking for a cleaner easier way to add search to this app. It doesn’t have to be side list. I would actually prefer search bar. Do you know of example of this? Can you send my way?

    Any help with respect to this is appreciated.


  • bobcubsfan

    Assuming you have access to Apple Dev, here is the link

    If not, give me your e-mail and I will send you the DMG for TableSearch

  • http://NA Chris McIntosh

    I am having an issue with transitioning from the main view to the second view, it errors out giving this: -[RootViewController taskViewC]: unrecognized selector sent to instance 0x44f8b0′

    I am actually extending the sqlLite app, but figure this would be a good spot to start as this is where the transitioning code i based it on was from.

  • BrewersFan

    Thank bobcubsfan,

    for some reason I did not see TableSearch Code last time I look in Dev Center Site.

    I will give it a try and let you know.

    thanks again…

  • http://NA Chris McIntosh

    okay, fixed it. I forgot to add a synthesize line in for my view.

  • bobcubsfan

    Okay, Brewersfan, good luck.

  • http://NA Chris McIntosh

    Question about libraries. Cant get into the forum because it wont accept my password. Anyway:

    Does anyone know what the library is for the iPhone’s camera functions and if there is some docs anywhere on accessing it?

  • http://icodeblog.com Brandon

    Why won’t it accept your password? It should have emailed you a temporary password. Sometimes if you do a copy and paste from this email, you get an extra space at the beginning or end that causes an error.

  • marcus

    Thanks for posting the code. I missed the “==” in the nil comparison. I only had a single = sign. If I had a nickel for everytime that has messed me up.

  • BrewersFan

    All, bobcubsfan, Brandon,

    Does anyone know how to change font size / make text in UITableView wrap around? My “Fruit” names in my array are long and I get this:



  • Bob Schoenburg

    Does this help?

  • BrewersFan


    thanks for post. I am looking to do what is guys is asking. I have looked at the apple sample code on this and still can’t figure out.

    It seems like this should be easier to implement..

    In my tableview I can change

    background color
    size of table

    but not the font size or create word wrap..

    Still confused…

  • http://www.storypixel.com Sam Wilson

    Awesome tutorials, one question… why did you do this:
    IBOutlet UITextView* fruitDescription;

    instead of this:
    IBOutlet UITextView *fruitDescription;

    Are they different?

  • http://icodeblog.com Brandon


    I did do it like this:

    IBOutlet UITextView *fruitDescription;

    I don’t think it would compile the way you are suggesting that I coded it.

  • John


    Thanks for the great tutorial. One quick question–how does one change the title of the back button, so that when “Watermelon” is selected, the back button reads something else, like “Index”, instead of “Fruits”?

    Any help would be appreciated!

  • http://icodeblog.com Brandon

    The title of the back button is determined by the title of the view you are going “back to”. So if you want it to say Index, title your rootViewController “Index”

    So where I have self.title = @”Fruits”; you could change it to self.title = @”Index”;

    Hope that helps!

  • John


    Thanks for the help–that works, but it changes the title too. I’m trying to do something like the Facebook app, where it shows “facebook” on the Navigation Bar, but “Profile” or “Chat” once the next view is loaded. Is there any way to disconnect the back button title from the title of the previous view?


    PS – I was looking at the documentation of the UINavigationItem class and its backButtonTitle property, but I’m pretty new to this and unsure *when* to change this property and from which view controller…

  • Bob Schoenburg

    Try this:

    comment the line:

    self.fruitView.title = [fruit name];

    in RootViewController.m

    then and this in FruitViewController

    //If you need to do additional setup after loading the view, override viewDidLoad.
    - (void)viewDidLoad {

    self.title = @”Chat”;


  • Adam


    Is it necessary to release the NSMutableArray *fruits in dealloc method as shown below?

    - (void)dealloc {
    [fruits release]
    [navigationController release];
    [window release];
    [super dealloc];

  • john

    Great stuff here!

    I am trying to extend the fruit example, with only 1 change, but that is enough to stump me ;-)

    I just want to have 2 UITableViews on the main page (each 1/2 of the view). Is this possible starting with the ‘nav based app’ that we are using for the fruit example? I am not sure how to change the name of the original one ‘tableView’ If I could rename it to toptableView, I might be able to figure it out ;-)

    Any pointers from anyone?

  • http://icodeblog.com Brandon


    Its not necessary but great practice. I was a little lazy and should have put it in. Great catch!

  • Jim

    First of all: thanks for this great tutorials. It’s very helpful for me!

    Following the tutorial, I created the Fruit project. Everything was fine until I pushed a fruit item from the fruit table. I got the following problems.

    Fruit[6749] *** Assertion failure in -[UILabel setTextColor:], /SourceCache/UIKit/UIKit-738/UILabel.m:288

    Fruit[6749] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Invalid parameter not satisfying: color’

    Any pointers to this are appreciated?


  • Jon K

    Again, great tutorial! Thank you!

    1 suggestion. In the ‘didSelectRowAtIndexPath’ method I set the title and description of the fruitView first, then added it to the navigationController stack. If you add the view to the stack first, you will see the title of a previously viewed fruitView just for a split second and then it will change the title.

  • amar

    This is really a very good tutorial…
    Good work Brandon! :)

  • AndyB

    @Jon K

    I just tried the change you suggested and changed the code in didSelectRowAtIndexPath to look like this:

    self.fruitView.title = [fruit name];
    [self.fruitView.fruitDescription setText:[fruit description]];
    [self.navigationController pushViewController:self.fruitView animated:YES];

    It fixes the problem with the title display but…

    The problem is that when I run the app the first time I click on a fruit the description is blank. After that every time a fruit is selected the correct description is shown.

    Is there something else I need to change to make this work?


  • corey

    In the method:

    - (void)viewDidLoad

    you delete the line where you call super:

    [super viewDidLoad];

    Is it not necessary to call super if you implement the method?

    Thanks for al the help on your blog….

  • http://icodeblog.com Brandon

    It’s good practice, because it will be required if you overwrite more complex functionality. However, it’s not 100% necessary.

  • billgajen


    Its amazing.. It helps me a lot. Thank you so much.

    But I have doubt,

    How to do like UITableView to UITableView..

    I mean, in the table when you tab on a cell that should bring another table. for example 1st one is main menu then when you choose one that should give you a submenu! I know its possible

    but if can let us know pls


  • Mike

    Brandon – thanks for the example…..I do have one question though. I am trying to show two fields in the cell.text and seem to be having problem….basically, this is what I am trying to do:

    cell.text = f.firstname && f.lastname;

    Question is – how do I concatenate two fields in C – I am not too familiar with C. Also what if one of these fields was a date field?

    For eg:

    cell.text = f.name && f.dateofbirth

    Thanks for your help!!


  • http://icodeblog.com Brandon


    Appending strings in Objective-C is a little different than in other languages. I don’t know why Apple just didn’t make it so you would write String foo = foo + bar.

    So to append string you would do something like this:

    NSString *name = [[NSString alloc] initWithString:f.firstname];
    [name stringByAppendingString:f.lastname];

    cell.text = name;

    Does this make sense? It’s quite a bit of code just to append a string to another string. Let me know if you need more help.

  • billgajen

    Hi brandon,

    Why you ignored my qustion?

    I am trying to do some thing in apps. as a beginner I need some help

    pls help me

  • http://icodeblog.com Brandon


    Sorry, it took me so long to respond. The question you are asking would take more than just a few sentences to answer. In fact, I could do an entire tutorial on it.

    I get a lot of requests for such a functionality and will consider doing a tutorial on it in the future.

  • http://www.theluiz.com theluiz

    I followed your code exactly only naming all the variables and files differently, and there are no errors or warning when building; however the UITableView is empty! :O
    I looked through the code and found no differences to your code (only with my variables)… Please help! :P

  • http://www.theluiz.com theluiz

    ahh nvm found it…
    forgot the

    return self;


    - (id)initWithName:(NSString*)n subject:(NSString *)subj description:(NSString *)desc duedate:(NSString *)due {

  • http://icodeblog.com Brandon


    haha nice. It’s always something simple… I’m glad you were able to get it working.

  • http://www.athenadesign.co.uk/blog/index.php/archives/58 iPhone Application And Website Development: All Tools And Tutorials You Need | Athena Design – The Lounge

    [...] Populating UITableView With An NSArray [...]

  • http://www.theluiz.com theluiz

    how would i add an object to this array? thanks in advance!

  • http://icodeblog.com Brandon


    It’s pretty simple.

    Fruit *peach = [[Fruit alloc] initWithName:@”peach” description:@”fuzzy on the outside”];

    [self.fruits addObject:peach];

    Does this make sense? I’m on the city bus responding from my iPhone so sorry if there are any typos. Let me know if you need more help.

  • http://www.theluiz.com theluiz

    ah ok makes perfect sense… thanks alot for the replies!

  • http://www.theluiz.com theluiz

    ok one more question (maybe the last ^_^)…

    how would i add an uiimage to the list of
    NSString *name;
    NSString *description;

    such that when i add an object to the array, i just need to specify

    initWithName:@”hello” description:@”hi” picture:@”icon.png”

    and i could then simple set a uiimageview to this image? sorry if im not making sense :P

  • wmparry

    I know this is a bit of an old subject, but just working through the tutorial and I’ve got stuck on the Connection Inspector part. I can’t get the fruitDescription Outlet to connect to the UITextView. I can connect the View to the FruitViewController, but the former just won’t play. I’ve double checked my code in FruitViewController.h and .m and I can’t spot any error except that my *fruitDescription is grey shaded like the screen shot.
    Thanks in advance for any advice. Great tutorials though.

  • http://icodeblog.com Brandon


    Did you make sure and complete the step when you select FruitViewController from the drop down on the Identity Inspector of the File’s Owner object? This would be the first thing I would check.


    in Fruit.h

    // Declare the UIImageView
    UIImageView *picture;

    // Make it a property
    @property(nonatomic,retain) UIImageView *picture;

    // Modify the initWithName method signature

    -(id)initWithName:(NSString *)n description:(NSString *) desc picture:(UIImageView *) pic;

    in Fruit.m
    // synth the UIImageView
    @synthesize picture;

    // Update the initWithNameMethod
    -(id)initWithName:(NSString *)n description:(NSString *) desc picture:(UIImageView *) pic {
    self.picture = pic;

    That should do it!

  • http://www.theluiz.com theluiz

    ok thanks so much! :D

  • http://www.theluiz.com theluiz

    ok so i made picture blank.png in my object that gets created on startup, however in didSelectRowAtIndex i put this
    [self.workView.workPic initWithImage:[homework picture]];
    and it does not work… i also tried this
    [self.workView.workPic setImage:[homework picture]];
    with no luck :(

  • wmparry

    Hi, yes, as far as I can see, I’ve followed the tutorial to the letter. I’ve even recreated the View from scratch. Dragging the circle from the fruitdescription outlet just won’t connect to the text view. Not sure what to do now.

  • http://www.theluiz.com theluiz

    sorry fixed mine !!! :D

  • http://web.mac.com/ostros/iWeb/iPhone%20Apps%20Entre%20Pilotes/HOME%20%28FR%29.html Deamb

    Hello again Brandon,

    Incredibly clear tutorial…! thanks

    If I may, one quick question:

    How complicated would it be to populate a tableview from an SQlite db retrieved on-line (so as to have up to date data ?), that could be refreshed at will a little like the currency rates in many apps ?


  • Josh Chaney

    How can I put a hyperlink in the descriptions ( after clicking on of the rows? I’ve googled everything, and it’s not clear to me from reading any of the docs in the dev center. Or what would work even better for me would be to have each row be an actual hyperlink. Since there is no google maps integration, I’m trying to build a tableview with rows that go to certain websites.

  • Eric

    I feel totally dumb. How does one get a program onto the iPhone. I went to Build>Compile, but that didn’t do anything.

  • http://icodeblog.com Brandon


    don’t feel dumb. It’s a legit questions. You can’t get apps on to the iPhone without paying the hundred bucks and getting accepted to the developer program. After this you will get a signing certificate to bundle with your app.

    The solution for you at this point is to test the app in the iPhone simulator. At the top of XCode you should see a button that says “Build and Go”. Click that and it should launch the simulator by default.

    Let me know if you have any more troubles…

  • mha

    So next dumb (sorry legit :) question is: is simulator reliable enough, that all testing can be done using this simulator only?

  • http://web.mac.com/ostros/iWeb/iPhone%20Apps%20Entre%20Pilotes/HOME%20%28FR%29.html Serge O.


    I guess the answer would be… no !

    I spent quite a lot of time developping an app with a NSNumberFormatter, which worked fine on the simulator… When I built to my iPhone, it did not !
    It turns out it’s a known issue…

    So, you can’t be totaly sure…

    Plus, apps on the simulator run super fast( mac CPU…), you only get a good idea of the fluidity of your app from running it on a device.

  • Eric

    Thanks for the info. I’m very new to programming and was excited to get an app out there. I was planning on the making the app free. But if I have to pony up $99 then I might just need to charge 99¢

  • Will

    This tutorial is great, but I think I’ve followed all the steps, and I’m getting a crash when I click on a fruit:

    2008-10-11 18:42:59.372 Fruits[41233:20b] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘-[UIViewController loadView] loaded the “FruitViewController” nib but no view was set.’

    Am I missing something here? here’s my code:
    FruitsAppDelegate *appDelegate = (FruitsAppDelegate *)[[UIApplication sharedApplication] delegate];
    Fruit *fruit = (Fruit *)[appDelegate.fruits objectAtIndex:indexPath.row];
    if (self.fruitView == nil) {
    FruitViewController *viewController = [[FruitViewController alloc] initWithNibName:@”FruitViewController” bundle:[NSBundle mainBundle]];
    self.fruitView = viewController;

    self.fruitView.title = [fruit name];
    [self.fruitView.fruitName setText:[fruit name]];
    [self.navigationController pushViewController:self.fruitView animated:YES];

    Sorry to bug you like this, but I’ve just been staring at this code and I can’t figure out what’s wrong.

    I’m also getting the same problem as @wmperry above, I can’t get the bubble from my IBOutlet to connect the dots with the TextView on my custom view. Is there any chance that this tutorial is out of date with the newest version of XCode/Interface Builder? Otherwise I think I’ve missed some crucial step.

  • Will

    I should also add that my “view” does not look like your screenshots. For one, my window header says “Custom View” instead of “View” and the background is greyish and has text on it. Has something changed between when you made your tutorial and now? I just downloaded this Interface Builder today. I feel like there’s some step I’m missing to set this view as the main view for the Nib.

  • Will

    Found the problem. I was creating a “Cocoa” view instead of “Cocoa Touch”. @wmperry, was that your problem too? Even if it wasn’t, please say yes so I don’t feel like the only idiot here who didn’t catch that.

  • Will

    No, ok, still not working. Can you clarify something? Why are you importing “RootViewController” into your application’s delegate implementation, if you never reference it?

  • Will

    OK, got it- that was my mistake- i didn’t do the second step with dragging the view. Sorry bout all my wasted space comments. Keep up the good work!

  • http://na Alan

    Hey – I noticed that by default when I create a nav type project – I get the following in my FruitAppDelegate.h file

    @interface FruitAppDelegate : NSObject {

    UIWindow *window;
    UINavigationController *navigationController;

    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) IBOutlet UINavigationController *navigationController;


    Which is the opposite of your file where your variables are of type IBOutlet and your properties are of type UIControl

    I haven’t managed to get through this one yet.

  • Steve

    Really great tutorial! Thank you so much!

    I was wondering if anyone could help me initialize the table to be one of those that have rounded corners and group the data into separate white rounded rects on a blue background. I believe it is using a style called UITableViewStyleGrouped but I cannot get it to work.

    I realize that I will have to alter the NSMutableArray to divide up the data into sections but that is the second step. I would feel progress if I could just get the data in the this tutorial to appear in a rounded rect.

    Of course if anyone has a sample of how to create the array that would be great as well! :)

    Thanks again! I look forward to going through your other tutorials, this one was the best iPhone tutorial I have ever seen.

  • MGC

    “For this tutorial I have chosen a UITextView as opposed to a UITextBox. This is because a UITextField is multi-line and is great for displaying more than one line of text.”

    You list 3 different UI objects in this phrase. Is the the 3rd one supposed to be UITextView or UITextField?

  • http://icodeblog.com Brandon


    Good catch, this was a type-o and I have fixed it. Thanks for pointing that out…

  • Kr1sh

    Hi Brandon, This is a great tutorial for what I wanted to do. However, I wanted to display a webpage in UIwebView when i tap a cell in table view, for example table view will have options like google, apple. When I tap google it displays google web page in UIwebView. I tried using couple of methods like NSURL request and so on..still i cant get it to work.Im not a programmer but with all your tutorials, i got confidence that I could do something…please help me with this..Thanks

  • Steve

    Pardon me if I am being dense but could someone please help me alter this code snippet from my project (which is based on this most excellent tutorial) so that the table is initialized using UITableViewStyleGrouped?

    I have tried everything i can think of but I seem to be messing up. I assume this is a relatively simple thing…

    Any assistance would be greatly appreciated!

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

    static NSString *CellIdentifier = @”Cell”;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

    MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    Park *p = (Park *)[appDelegate.parks objectAtIndex:indexPath.row];
    [cell setText:p.name];

    // Set up the cell
    return cell;

  • http://icodeblog.com Brandon


    What seems to be the error message that you are receiving? You would see this appear in the console…

  • Steve


    Thanks for the quick reply!

    I just realized that I had been making an error in trying to set the style of the list in the following line of code:

    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

    rather than by simply setting the style in the root view controller using IB. Oops! :)

    Now I am trying to figure out how to add a toolbar below the list view. Any suggestions?

    Also, is there a good way to put a toolbar at the top of an application just below the Navigation controller titlebar? I am trying to make something that allows users to select a day with something like the control in the calendar app which displays a left and right arrow and the current date. I don’t see an obvious direction.

    The toolbar at the bottom that I asked about above is my compromise since I have seen it so I know it can be done.

    Again, I can’t tell you enough how helpful your tutorials have been!


  • SFGiantsFan

    Hi All! And thanks Brandon for a very helpful site! I really appreciate the level of detail you’ve put into it. And as I slowly go through every line I really try to understand EXACTLY what’s going on… And I think I do…except with these calls to UIApplication. Specifically:

    FruitAppDelegate *appDelegate = (FruitAppDelegate *)[[UIApplication sharedApplication] delegate];

    Could someone give a DETAILED explanation of what exactly is happening here? You are setting a pointer to the Application’s Delegate. But because FruitAppDelegate is a class isn’t it also an object? And as such couldn’t you just send IT a message asking it to reveal its delegate:

    *appDelegate = [FruitAppDelegate delegate]

    I know there’s some typecasting going on but WHY is each piece necessary?

    I know this could be a junior question and I apologize in advance…but would really appreciate anyone who could clear it up for me. Thanks!

  • Steve

    I am really stumped trying to figure out how extend this tutorial to add a toolbar with a couple of buttons to the bottom of the list of fruits. It should be part of that table view and thus not be visible on the fruit detail view.

    Should this be done in Interface Builder or code? I have tried both without success.


  • Bill

    Along with everyone else, thanks for these tutorials. My question is:
    Should I be able to follow this example and do everything the same except rather than using a UIViewController Subclass, use the UITableViewController Subclass?
    I of course don’t use a UITextView in my class, I just used a UITableView for my IBOutlet and I created a property and synthesized that property.
    As soon as I get to the line:
    [self.navigationController ....] it breaks into the Debugger with no real indication as to why.

    Any ideas?

  • ElegantMac

    Brandon, just wanted to add to the accolades of others…your tutorials are awesome and you’re always finding ways to top yourself, even w/ a heavy CS load. :)

    Anyway, just something to add to this and your other table-based tutorials. One thing that’s helpful as a visual clue that a cell is “drill-downable” is a nice disclosure indicator. I didn’t see a way to do this with Interface Builder, but adding this to the cell’s specification works:

    [cell setAccessoryType:(UITableViewCellAccessoryDisclosureIndicator)];

    Added your site to my list of RSS feeds, keep up the great work!

  • Lakario

    Great tutorial. Incredibly helpful!

  • ElegantMac

    Hi Brandon, since you mention in the FruitViewController creation that XCode never seems to add files where you want, try this:

    >> In Xcode, in the project organizer select either the project (Fruit at the top of the Groups and Files list) or the Classes group folder—the new files will be added to the current selection.

  • Andreas

    @SFGiantsFan: Internally in Cocoa, classes are also Objects, so strictly speaking, you’re right. But classes only understand class methods (prefixed with “+”) and object instances only understand instance methods (prefixed with “+”). That’s why the class FruitAppDelegate doesn’t respond to the “delegate” method/property.

    Here’s a short breakdown of what’s happening in the line:

    FruitAppDelegate *appDelegate = (FruitAppDelegate *)[[UIApplication sharedApplication] delegate];

    This is the same as the following sequence of statements:

    // Call UIApplication’s *class* method +sharedApplication
    // which returns the one and only Application object
    UIApplication theApp = [UIApplication sharedApplication];

    // We then ask the Application object for it’s delegate
    // (a FruitAppDelegate instance)
    FruitAppDelegate *appDelegate = [theApp delegate];

    If I’m not mistaken, casting is not strictly necessary here.

  • Andreas

    Of course object methods are prefixed with a minus sign (“-”). Sorry for the typo.

  • Jitesh


    Thanks for the tutorials ..it really helped me a lot …

    As an enhancement i want to add the fruit icons besides the name of the fruit …. same as iphone application has shown in setting option …. how can i do this … please give me reply on my mail account if possible .

  • http://icodeblog.com Brandon


    Follow my SQLite tutorials. I detail how to do this.

  • Edward

    Hi.. Brewersfan wrote back in august about adding an email button to the fruitviewcontroller view window. I plugged in all the code he gave and i added the button and linked the touchdown property to the emailfruit procedure. when i click on email, it doesn’t do anything. Can someone help?

  • http://www.sakrist.com/ SAKrisT

    Good work…
    Thanks for the tutorial…

    will be the time that something like this and seriously write

    Good luck :)

  • Ricardo

    Hello, and thanks for these awesome tutorials.

    Im stuck at this part:

    Now, click the circle next the word View under outlets and drag it to the View object inside of the window that says FruitViewController in the title.

    I dont have any windows with FruitViewController in the title in my interface builder. Can anyone point me out to what I’m missing in this step?


  • Ricardo

    Ah nevermind, i figured out my error! Instead of calling the view object just by view i called it table view. So i couldn’t find any object called view. Now I get it!

  • Joeri

    I don’t know why but I’m getting the following errors in FruitAppDelegate at the following lines

    Fruit *apple = [[Fruit alloc] initWithName:@”Apple” description:@”Red Delicious are my favorite”];

    warning unused variable “apple”

    Fruit *orange = [[Fruit alloc] initWithName:@”Orange” description:@”Mmm…. Fresh squeezed orange juice”];

    warning unused variable “orange”

    Fruit *watermelon = [[Fruit alloc] initWithName:@”Watermelon” description:@”My favorite favorite flavor of Jolly Ranchers”];

    warning unused variable “watermelon

    Everything else matches perfectly… Any ideas?

  • Joeri

    Found the error… typo :s

  • Gero

    Hey Brandon.

    Thanks a bunch for your very well written tutorials. Chewing through Apple´s example projects with some date here, some constants there and “oh, we prepared the Localizable.strings file so you have to switch back and forth to understand which localized string says what” are monsters to digest for beginners like me.

    One Question, though.
    Do you know how to pop up a tableView two steps up in the navigation hierarchy? I implemented a “Save”-Button which is supposed to bring you back to an overview tableView.

    I found that you can call [self.navigationController popToViewController:upTheLadder animated:YES];

    So far so good, it expects the upTheLadder refference, though and all my attempts of creating a lokal refference were futile so far, because obviously the navigationController will only pop up the upTheLadder view it already knows.

    So how do I get my navigationController´s refference to that specific View?

  • Darryl

    Hey Brandon,

    I have tried a couple of your tutorials and every time I get to the part where I am connecting the view to the class.

    “Identity Inspector. Select FruitViewController from the dropdown next to class. ”

    FruitViewController is not in the dropdown.

    The same happened when I tried your views tutorial.

  • Gero


    You have to create a new class file and then in IB make sure you have the “File´s owner” selected.

    Maybe you have to reload all class files?

  • Edmond

    Hi Brandon,

    I am new to iPhone programming, thanks for the tutorial, it helped me a lot.

    I have a question regarding the fruitDescription, how to modify the fruitDescription to display content from a rtf/rtfd file?


  • MauiG

    Great tutorial Thanks!

    In response to Luis and the UIImage View wouldn’t you need to change this code in the RootViewController.m file? I just cant figure it out. I was also trying to add a ‘phone’ and ‘url’ field as well using the same priciples? Thanks again…

    [self.fruitView.fruitPicture setText:[fruit picture]];

  • mz

    Hi Brandon. Much thanks for the hard wrk you have put in!

    Question: Should dealloc in FruitAppDelegate.m have the following to release memory?

    - (void)dealloc {
    for (Fruit *fruit in self.fruits) {
    [fruit release];
    [self.fruits release];

    [navigationController release];
    [window release];
    [super dealloc];

  • http://iappdevs.blog.co.in/2008/12/27/todo-list-application-iphone-programming/ Todo List Application -iphone programming | iPhone App Devs

    [...] while still explaining the new stuff in detail.  I will assume that you have completed the fruits tutorial and it’s [...]

  • Brian

    Thanks Brandon for this great tutorial.

    For some reason i’m getting an error: _TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION_ when I click on any row on the first page, if I click on Apple nothing happen.

    Anybody knows what is going on? Thanks in advance.

  • Brian

    My fault, misspelled the viewController. It’s working fine now.

  • Rudy

    Thanks Brandon for this great tutorial. I downloaded your source and it compiles and runs just fine.

    As soon as I select a cell from the table view and I push the new view to the navigation controller my app crashes and I get:

    2009-01-01 13:16:01.874 Logweb Touch[1330:20b] *** Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.’
    2009-01-01 13:16:01.876 Logweb Touch[1330:20b] Stack: (

    Anybody knows what that means? I have done everything as stated in the tutorial (at least I think I did) and I have compared Brandon’s source and Nibs with mine and they look quite identical. Anybody who can help me with this issue?

    Thanks in advance! And a Happy New Year everyone!

  • D.

    How can I write, for exemple: I “love” Apple, with quotations?
    If I write Fruit *apple = [[Fruit alloc] initWithName:@”Apple” description:@”I “love” Apple”];
    I got an error. Thanks.

  • http://www.musicfusion.com Diego

    Hi… I´m triying to implement an UIImageView (as you explain it to theluiz) to load a picture (located in the application) in my fruitview.
    I´ve tried everything but nothing :( . Maybe could you send me a fullcode, o paste it in the website.
    Thanks & Regards

  • C.

    Hi, I tried to do this tutorial but I keep getting the error:

    Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘-[UIViewController loadView] loaded the “FruitViewController” nib but no view was set.

    I don’t know why. Could you please help me out?

  • http://violetoakley.com Stephen James

    Fantastic Tute. I created my first app from approximately 300 tutorials, but of all of the I found yours most useful. I submitted it on Dec 30, it was sent back January 6 because of inappropriate table feedback issues (the reo turned blue and stayed blue).

    I fixed that and also changed the disclosure thingies from the plain chevron to the blue circled chevron. I resubmitted on the 7th and it was approved on Jan 11. Whoo – hoo.

    Oh, the name of the app is iGreyhound.

    Right now I am learning how to make a tabBar pull up the three different clubs (you’ll see what I mean if you download it (for free).

    I also want to learn how to store use local images – right now I know how to pull them from the web (but that would mean data charges for my unsuspecting app downloaders) or I can put one image in view. Like I said, I’m working on it.images on the resource. Thanks again for the tute.

    Regards – Stephen

  • me

    More explanations!!!

    I’ve seen so many tutorials, and each of them explained why you have to do exactly like this.
    Not for this one!

    You just keep saying “type this and it’ll do that!”, without any explanation.

  • http://www.freshapps.com Brandon


    What was unclear?

  • Dezorian

    Thanks for this great tutorial! Finally found what i was looking for.

    But i’m having problems though:

    I’ve build the application excaclty as your samplecode (downloaded the app for comparing every file). But i can’t seem to build my app properly.

    I get an error at the following line in the rootviewcontroller:
    [self.fruitView.fruitDescription setText:[fruit description]]

    ‘error: request for member “fruitDescription” in something not a structure or union’

    if i comment the line, the program runs but crashes at startup with the message “__TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION__”which is thrown in the main() method.

    If i run your sample code from this tutorial it runs fine. I checked every line of code and all the properties in the interface buidler. I’m getting desperate.

    Do you have any ideas where to look for this? Thanks in advance.

  • Manish


    I am working on same type of application using XML but need to extend it like i need again a table view on second view. Application flow is like

    Books category(First TableView)->Books List(Second TableView)-> Books Details (Customized View)

    Dont know how to add a TableView on second view. I tried to add A TableView on second view by dragging it(also created controller for it) but got exception(…..unrecognized selector sent to instance…….).

    Can anybody help me to understand it.

  • James

    Hi Brandon, Great tutorial.

    I have been trying to add a UIImageView to each fruits page to display an image of each fruit along with the description. Im having trouble getting the image to actually appear. I have:
    -given each fruit object a UIImage *fruitPicture
    -added a IBOutlet UIImageView to the fruitViewController, — initialized the view and set the image
    -used Interface builder to connect the outlet to the view

    Could you suggest the correct way to do this?


  • MauiG

    I am having the same problem with UIImageView, and have tried everything – If anyone could help with this that would be greatly appreciated!

  • daniel

    Why are you declare “NSMutableArray *fruits;” at fruitAppDelegate?
    Can’t yoy declare at RootViewController ??

    And why there are property “retain” and others “copy”

    Thanks so much.
    PD:sory my english!

  • CLAD

    help Im having trouble with this step I have done this step over about 4 times and I mean from the beginning the first go round it worked and I was able to connect and complete the app ut when I ran it it crashed so I started over I thought it would be easier HMMMMm anyways Im still a NOOB and need help here is the prob

    Click Tools -> Identity Inspector. Select FruitViewController from the dropdown next to class. Notice that under the Class Outlets section you will see the UITextView property we created.

    But in the Class Outlets there is no UITextView .

    here are my lines of code with my differences ignite instead of fruit.



    @interface igniteViewController : UIViewController {
    IBOutlet UITextView *igniteDescription;


    @property(nonatomic,retain) IBOutlet UITextView *igniteDescription;



    #import “igniteViewController.h”

    @implementation igniteViewController
    @synthesize igniteDescription;
    // The designated initializer. Override to perform setup that is required before the view is loaded.
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    // Custom initialization
    return self;

    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {

    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
    [super viewDidLoad];

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);

    - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn’t have a superview
    // Release anything that’s not essential, such as cached data

    - (void)dealloc {
    [super dealloc];

    I hope somebody can help me thanks

  • MauiG


    Did you ever figure out the answer? I followed the instructions above that were given to Luiz… The only problem is in the detailed view controller. Which Luiz solved above but did not given his solution:

    This will work to get the same image on each page
    UIImage *img = [UIImage imageNamed:@"apple.png"];
    [[[self fruitView] fruitPicture] setImage:img];

    But when I try anything like these statement to pass the image it won’t work..

    [[[self fruitView] fruitPicture] setImage: fruit picture];

  • Kevin

    This is killing me. I can’t find the answer anywhere.

    How do you create an image array instead of text? I’d like to create an app similar to the one you have here, except, when the row such as “apple” or “orange” is pressed, you’re taken to a view that has the name in the nav bar, the description in the textview just like yours has, but also I’d like to add an image of the thing you pressed. The app I am working on has 220 rows. I’d like to load in an image into the view along with the description when the row is pressed. How do I do that without creating 220 nibs?

  • MauiG


    You can look at the instructions that were given to Luiz… It shows how to add an image. Then you just need to figure out the last line of code that I mentioned above. Luiz seemed to be able to figure it out…

  • CLAD

    @Brandon first of all thanks for this tut it rocks.
    I figured out the last trouble it was a simple error
    but now I have just a few error’s coming up.

    In RootViewController.m
    the error reads
    ” no declaration of property ‘fruitView’ found in the interface.

    here are my lines of code

    #import “RootViewController.h”
    #import “fruitAppDelegate.h”
    #import “fruit.h”

    @implementation RootViewController
    @synthesize fruitView;

    any ideas?

  • CLAD

    k I got the last one to work but i cant figure this on out Im getting 2 code error’s

    In the RootViewController didSelectRowAtIndexPath line

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic
    FruitAppDelegate *appDelegate = (FruitAppDelegate *)[[UIApplication sharedApplication] delegate];
    Fruit *fruit = (Fruit *)[appDelegate.fruits objectAtIndex:indexPath.row];

    “HERE ARE THE ERROR messages”.
    error:syntax error before ‘)’ token
    error: syntax error before ‘objectAtIndex’

    so thats it any help would be great thnx

  • Zpeskin

    i am having a problem with a simple variation of this tutorial

    When i try to push the details view i get an uncaught exception error – it says the nib file loaded fine but the view connection was not made.

    I checked in IB, but the view was connected to the controller file for the second view. Any ideas?

  • BoxBoy

    @Brandon I am having a problem with In the:

    “RootViewController didSelectRowAtIndexPath line”

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic
    FruitAppDelegate *appDelegate = (FruitAppDelegate *)[[UIApplication sharedApplication] delegate];
    Fruit *fruit = (Fruit *)[appDelegate.fruits objectAtIndex:indexPath.row];

    “This is what the messages are saying”
    error:syntax error before ‘)’ token
    error: syntax error before ‘objectAtIndex’

    Hey thanx for this Tutorial is awesome man and for your reply.

  • Fabio

    Hi, great tutorial, but I have a question:

    I added the fruit Lemon and as a description I retrieve the content of an internet page. But how can I retrieve the content of a local txt or rtf file instead of an internet URL?
    Can’t really figure how to do it…
    Thanks :)

    Fruit *watermelon = [[Fruit alloc] initWithName:@”Watermelon” description:@”My favorite flavor of Jolly Ranchers”];
    Fruit *lemon = [[Fruit alloc] initWithName:@”Lemon” description: [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.icaramel.com"]]];

  • Kevin


    How did you connect the UIImageView in interface builder? My FruitViewController nib doesn’t show a “picture” outlet that I can connect to the UIImageView. When I add one by hand, the app crashes when a row is selected.


  • Julien

    hey Brandon,

    First I just wanna say thanks so much for the epically awesome tutorials.
    Well I just have one question, say I wanted the 2nd view to display formatted web based content, what would I do in this situation?


  • fskhalsa

    Sweet. Nice tutorial!
    I just spent an hour doing this, and I’m still deciding whether it’s fully fulfilling or not to see an app that does as little as this after all that. I’m sure that’s just the first time though, and if I knew what I was doing, it would take only 15 minutes.
    Either way, even though I don’t understand most of it, I’m still learning a lot, so Thanks!
    Keep writing tutorials!

  • fskhalsa

    I have one question Brandon. I’m trying to add pictures of fruit to my app. I followed all your instructions to Luiz, and added the image view and connected it. Each fruit has it’s own image assigned like this: picture:@”apple.jpg” etc. The problem is that I don’t know where to put the pictures so it can find them. The app runs, just there is a blank space where the pic should be. I’ve tried putting them in the project directory, and tried dragging them into xcode. I’m a total noob at this, so there is obviously a place for them, I just don’t know where. When I dragged them into xcode, i could select one of them in the attributes field for the uiimageview in ib, but then that image would appear for all the fruits. I want it to pick each image that I assigned differently for each fruit. Any help?
    Thanks a ton.

  • http://Drudoo.com Drudoo

    Really nice tutorial, but i still cant figure out how to change the text to a picture. I tried everything, from the comments.
    Can someone send me there project file(the one that got it to work) or can anyone explain it to me.
    I really new i programming, so any help would be great :D

    You can email me at:

  • Kevin


    You just have to drop them into your Resources folder. A dialog box will pop up asking you to add it to the project. Make sure you check off the “Copy” box.

    I also want to add images. I followed the instructions for theluiz too, but mine doesn’t work. I don’t see how to connect the UIImageView in IB when the First Responder doesn’t have an outlet.

    Any help?

  • Kevin


    @ MauiG

    Did you ever figure out the image problem?

  • Jonathan

    Thanks for the tutorial… Just starting on iphone dev after a few years without coding, and you’re of great help!

  • eXDee

    ok, I have the first tableview set up with an array of different choices to choose from. I have the interface for the second view set up, which is also a tableview. But what Im having trouble with, is inputting another array into the second view.

    I want for there to be a different array for each cell that is chosen in the first view. Any idea how I could get that done?

    it would be greatly appreciated.


  • Kevin

    @Stephen James

    Looking at your iGreyhound app it would appear you figured out how to place the text and an image on the same view. How did you get the images to appear for the selected row? We’re all trying to figure that one out.

  • Tim

    Excellent tutorial… I got everything working as your laid out and so I decided to stretch things a little and I have a couple questions.

    First, I changed out the TextView (UITextView) to be a Scroll View (UIScrollView) and made the changes to the IBOutlet and @property statements accordingly and then went over to Interface Builder and made all the connections. (all looks good)

    Everything compiled (with 1 warning) and the app fired up in the simulator it dumped. I am getting the warning that UIScrollView may not respond to -setText in the RootViewController.m file. This line [self.fruitView.fruitDescription setText:[fruit description]]; is where the problem is.

    In a nutshell I understand that setText isn’t going to work with UIScrollView, but I dont know where to go to figure out what will. I have read everything that I can get my hands on and I guess I am just missing it.

    Can you point me in the right direction??

    Also, assuming I get past this issue, in my example I have a lot more text that I want to put in the ScrollView or TextView then what you did in the tutorial and I was wondering if there was a way to force a line break in the text inside the description value that we set inside the FruitAppDelegate.m file? I was hoping to be able to bold or italic a specific word, but it appears that is not possible in TextView on an individual word basis, only on the entire text. If the answer is no to both TextView and ScrollView, what are my options to do this?

    Thank you very much! Excellent Tutorial.


  • Kevin

    Still trying to load in the images of the fruit. Why does this not work?

    in RootViewController.m

    //set name in the nav bar
    self.fruitView.title = [fruit name];

    //put description into the label on the view
    [self.fruitView.fruitDescription setText:[fruit description]];

    //put the image into the UIImageView
    self.fruitView.picture = [fruit picture];

    It build but crashes when I select a row. Maybe I need a line similar to the “description” one, although I don’t know how to do it.

    Please help. The name shows in the nav bar, the description shows on the label, but no image.

    twitter @RyeMAC3

  • http://www.webappuniverse.com Mark H. Delfs

    Another great tutorial! For future tutorials I would love to see more stuff about e-mailing results, location services, and things like that. As usual, LOVE these tutorials and please keep them up! I would buy a book of these in a heartbeat!

  • reetu.raj

    hi there @brewersfan,

    for changing font size for table rows text I have added following line

    cell.font = [UIFont boldSystemFontOfSize:9];

    in given below function:

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

    static NSString *CellIdentifier = @”Cell”;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

    // Set up the cell…
    cell.text = [specifics_menu objectAtIndex:indexPath.row];
    cell.font = [UIFont boldSystemFontOfSize:9];
    return cell;

  • Jinu C Joseph

    are the ringtone, wallpaper settings manageable/accessible from an app? If yes, how we can do this using the SDK. Thanks in advance.

  • http://ryemac3.net Kevin

    Twittered with Brandon this morning…

    …for those looking to solve the “load an image into the FruitViewContorller.xib” thing…

    …he says to “in viewDidLoad on fruitViewController do self.imageView.image =fruit.image and it will display the correct image for the fruit”

    I can’t wait to try this when I get home!


  • contact

    You are really GOD!!!!

  • http://ryemac3.net Kevin


    I’m so discouraged…

    “self.imageView.image =fruit.image” didn’t work.

    I tried “self.fruitView.fruitPicture = [fruit picture];”

    It builds OK, but crashes when I select a row.

    What I don’t understand is why “[self.fruitView.fruitDescription setText = [fruit description]];” works and “self.fruitView.fruitPicture = [fruit picture];” doesn’t. I am putting this in RootViewController.m along with “[self.fruitView.fruitDescription setText = [fruit description]];” since that is where the “fruitView” is talked about. I tried to put it in the FruitViewController, but it doesn’t build there. It complains about not knowing what “fruitView” is.

    Kevin / @RyeMAC3

  • john

    Thanks Brandon. Awesome stuff.

  • Austin


  • Mozo

    @wmparry I was just experiencing the same problem as you described… I couldn’t drag a connection from the fruitDescription outlet to the UITextView in my view. I found that in my case, this was because I had defined the @property incorrectly in FruitViewController.h.

    I had:
    @property(nonatomic,retain) IBOutlet UIText *fruitDescription;

    rather than:

    @property(nonatomic,retain) IBOutlet UITextView *fruitDescription;

    Once I corrected UIText to UITextView I was able to make the connection.

  • http://www.jal.com jal H

    great tutorial …


  • Brian Sterling

    Here’s how I solved the issue of the new .xib files not going into the project’s directory by default.

    Rather than starting Interface Builder by double-clicking any of the existing .xib files, do File:New File… directly from Xcode. Choose User Interfaces from the list on the left, then the desired template. Once you save, it will automatically be in your project directory.

    This works for me with Xcode 3.1.2.

  • welshbaloney

    Excellent tutorials. I’m a beginner and find that I follow along with the more complicated ones (like this) somewhat parrot-fashion. I.e., I can’t visualize what’s going on so I just copy the code.

    I’m learning from the code itself, but what would totally complete the learning experience would be a diagram, such as a design pattern diagram that shows each main object, controller, view, etc. their methods and the messages between them.

    Then I would better understand the WHY as well as the HOW.

    I realize you’re doing this on your own time, and thanks very much for that.

  • welshbaloney

    One other thing…I’m still getting confused over when/how to use a delegate vs. a controller. I get that (in this project) there’s a RootViewController that pairs with the MainWindow.xib and a FruitViewController that pairs with a FruitViewController.xib. But then that FruitAppDelegate pops in.
    I don’t understand why the fruits array (e.g.) was defined there instead of somewhere else….

    Am I making sense and can anyone just help clear this up for me?

  • sant

    Hi Brandon,

    Great tutorial. One question.
    Once the user clicks on fruit -> apple, how do i make the text in “apple” screen uneditable. I want a simple appl where the user clicks on one of fruits and reaches the fruit description which is basically read only.

    Any answers to that ?


  • sant

    Hi Brandon,

    Great tutorial. One question.
    Once the user clicks on fruit -> apple, how do i make the text in “apple” screen uneditable. I want a simple app where the user clicks on one of fruits and reaches the fruit description which is basically read only.

    Any answers to that ?


  • surfous


    You need to make the UITextView in the FruitViewController nib not editable.

    To do this, double click FruitViewController.xib to open it in the Interface Builder. From the window titled FruitViewController, click to select the TextView item (you may need to twist down the View item to see it). Alternately, you can click the UITextView in the interface window (it has the “Lorem ipsum” text in it).

    Open the atributes inspector (command-1) on the TextView. the inspector palette window should have the title “Text View Attributes.” In the very top section you should see Alignment, Text color and a checkbox named “Editable.” Uncheck this box, save & quit the interface builder.

    Finally, go back to Xcode and rebuild and run the code. The fruit descriptions should no longer be editable.

  • rbcrane

    Thanks for the great tutorials Brandon. I’ve been coding since the 80s, it’s been a while since I hacked UIs. These tutorials are helping it all make sense.

  • SomethingSpecial

    Nice screenshots you stupid f u c k i n g a s s h o l e.

  • Ryan

    Hi Brandon (or anyone who can help),

    There is a simple problem I have had for days. I need to get an NSArray created in one view controller passed into another one. The array is created when a user presses a button and then it gets placed into a UITableView using the other view controller.

    Since the array is always determined at real time, I cannot set it in myAppDelegate and therefore can’t use the appDelegate method,

    myAppDelegate *appDelegate=(myAppDelegate *)
    [[UIApplication sharedApplication] delegate]

    used to create an instance of the array for the table view controller like in this tutorial. Any ideas? Thanks!

  • ashwanik04

    Hi Ryan,

    Regarding your post, You can create a property in the child view and give it value when u r drilling to child view from parent view in the didSelectRowAtIndexPath method of the parent view.
    Hope it may help u.

  • Kawititnow

    Hey Brandon, and everyone else,

    This has been a great tutorial to get my feet wet with the iPhone SDK.

    I’m trying to expand a little bit on the app, and what I’m trying to do is make it so the user can add and delete fruits.

    So far I’ve added an addButton to the RootViewController. When the addButton is pressed a NewFruitViewController is “popped” up, which contains 2 text fields (1 for newFruitName and the other for newFruitDescription). I had implemented a Save button at the top of the navigation bar, but when I click it I “think” it has added the new fruit to the fruits array, but it does not show up in the RootViewController.

    Any ideas on how to insert the newFruit data into the fruits array and display the new fruit as a new cell???

    Thanks in advance

  • Kawititnow

    below is my code for NewFruitViewController.m with the save method:

    #import “Fruit.h”
    #import “NewFruitViewController.h”
    #import “FruitAppDelegate.h”
    #import “RootViewController.h”

    - (void)save:sender {

    NSString *name = newFruitName.text;
    NSString *desc = newFruitDescription.text;

    Fruit *newFruit = [[Fruit alloc] initWithName:name description:desc];
    FruitAppDelegate *delegate = (FruitAppDelegate *)[[UIApplication sharedApplication] delegate];
    [delegate.fruits addObject:newFruit];
    [newFruit release];
    [self dismissModalViewControllerAnimated:YES];


    My thinking was that if I can add the object to the array then the rest would take care of itself. Any help would be appreciated.

  • ashwanik04

    Hello Kawititnow:
    Instead of using
    [self dismissModalViewControllerAnimated:YES];

    [self.navigationController popViewControllerAnimated:YES];

    It will work :)

  • Kawititnow


    I tried that and when I went to hit the save button nothing happened. The only way I could get out of the modalViewController was if I hit the Cancel button, which uses the dismissModalViewController…

    So it seems it either isn’t adding the newObject to the array, or it isn’t reloading the table?!?

  • ashwanik

    I modified the fruit application code provided here with the requirement u said, it did work for me, if u can give me your email I can give the code, Of course with your permission onle :P

  • Chito

    Great tutorial!!!!!! VERY useful.

    I got everything to work. How do I get it so that the user can go back to main screen after they go to the fruit description. On the top it simply lists the name of the fruit that is being described.

  • Chito

    At the fruit description window it does go back to fruits when you click on the left side of the top bar on the window but there is no button present.

  • Kawititnow


    My email is


  • Chito

    solved the problem, I had to erase */ and /*

  • Kawititnow


    Feel free to email me the code that you have, as I’m still struggling.

    My email address is .


  • Mick

    I cannot get this tutorial to work. Two issues I’ve noticed. First, when I create the NSobject subclass Fruit, the file Fruit.h does not contain “#import ” but “#import ” instead. The import UIKit is found in the RootViewController.h file.

    Second, even if I put the import UIKit line in the Fruit.h file, it does not compile. I get the same “‘error: request for member “fruitDescription” in something not a structure or union’” error that Dezorian mentioned above.


  • Mick

    My last post came out wrong – it was suppoed to say that the Fruit.h file did not have the import UIkit line, but had import foundation.h instead…

  • Julius

    Regarding wmparry’s question about not being able to get the fruitDescription outlet attached to the TextView; check your FruitViewController.h file and make sure you’ve declared the fruitDescription property as a UITextView and not a UIText (if you’re like me you might have hit Tab to fill in the property type and not noticed that it doesn’t complete the full typename of UITextView.

  • sjalfr


    Worked like a charm, thanks. But I was wondering… When in the “description” view, if I click on the actual description, the keyboard pops up and there is no way to make it disappear!

    Going back to the fruit list and clicking on another fruit brings me back to the description as it should, but the keyboard is still out even without clicking on the description again.

    Any ideas on how to get rid of the keyboard, or better yet, not having it pop out if you don’t want the list to be editable.


  • Chito

    Thanks again for the tutorial. Worked great. I have purchased and Objective C book and a Iphone app book but you do a better job of explaining. If you have the time, can you please help with creating this same app but to have one more layer.

    First view( List of foods”vegetables,fruits,sandwiches,etc.”

    Next view(List of items in the categories of foods “Fruits-strawberries,pineapple,lemons,etc.”

    Last View( The description of each of those fruits).

    Please Help.

  • http://www.twitter.com/talltodd65 Todd

    From what I can tell there is going to be a memory leak in the app since the fruit objects are not being deallocated.

    Each [fruit alloc] needs to be released.

  • Anon

    Doesn’t anyone do anything in Obj-C without using IB? I, personally, greatly dislike using any form of graphic interface for programming. Maybe it’s an old habit from C and C++ but I don’t the idea of having a single line of code in my program that I can’t explain entirely.

    Does anyone know of any anti-IB tutorials out there?

  • Mike

    Is it possible to use this tutorial as a base to making editable text views (changing the description) which save using NSUserDefaults, or will it reset every time because the description values are predefined. If it is possible can anyone post some code that might put me on the right track?


    I got 21 errors by following your tutorial as it is.
    i am using xcode 3.1.2 is it some version problem bcoz
    when i load nsobject class i dont get
    header by default,, if i include it gives //no such header exists
    also in each function i get error like eg: for viewcontroller
    //undeclared in this function first to use


    Thankx For tutorial plz solve the error in ur code:

    i got error ‘ fruitdescription is not something like structure or function ‘ in RootViewController
    FruitViewController import statment in Rootviewcontroller is
    showing error like ‘ not found in this directory ‘

  • http://www.unisynergygroup.com Eric

    Hi Brandon,

    Thank you for your generosity and sharing your knowledge with us. I’m new at programming and find your tutorials very useful!

    I have a problem creating the NSObject subclass file. The only templates I have when I click File – New File are Objective-C class, Objective-C test case class, and UIViewController subclass.

    I just installed version 3.1.3 of xCode. Am I missing something? Thanks for your help :-)


  • Viswanath


    i’m newbie…

    I could not able to see the view. its just blackout on my simulator, but no errors as well.. i just did as what told above.. any idea or suggestions

  • http://www.unisynergygroup.com Eric

    Regarding my previous post – in xCode 3.1.3, you need to choose the Objective-C class template and choose NSObject from the «Subclass of» drop-down menu, and then remove the header and replace it with the header.

    Everything worked very well.

  • stevebillgates

    I am seeing the same as what Vishwanath mentioned…its a blackout screen…and also I see the app crashing :(

  • Viswanath


    I was looking into the log file and it say UIKit not found. .

    any help!


  • http://jcostaman.com John Costa

    Hey! Can you make a tutorial on how to add a search. If you already have, I’m sorry. I’m new to the site. It would also be VERY useful to add a search to the site! lol

  • J Mill

    I was just wondering if its possible to put images on the table instead of the fruit

  • Graham

    Hmmm…I keep getting an error after the applicationDidFinishLaunching portion. It’s for the three variables of type fruit (*apple, *orance, ect.). Keeps saying: error:syntax error before ‘objc_string’ token. Not sure why it’s doing this…looks like the rest of the code is compiling fine…

  • Ainn

    Hey, very nice tutorials.

    Is there a way to connect this tutorial with the game tutorial? Basically, if you press a button it starts the game up?


  • http://www.tutorialhelpcentre.com Matt

    Just want to say a big thankyou, just got a macbook for the purpose of making apps and found it so difficult, now I have gone from nothing to completely understanding everything youve explained and adapting it for my own app, going to continue with the tutorials now ^^ thanks again!!

  • Bryon

    Thank you for the help! I was able to use this structure to develop my app. All I wanted to do now is add a uiimageview on the drill down table to show with the descriptions. So for example, if you wanted to show a picture of a watermelon above your description how would you code it into your array?

    been trying to figure this out for the last 15 hrs :(


  • steve

    Personally I think this is an unhelpful method of teaching. The jpg code is nonsense – it turns the whole thing into a test of copy typing. I suppose there is some primitive idea behind this that somehow it does one good to copy a load of code – whose concepts you are trying to understand at the same time. Of course that is bollocks. One’s short term memory is merely being overwhelmed with checking commas and semi colons and square brackets while one’s mind would be better directed to more high level concepts like – the whole MVC pattern and how it is implemented here – the meaning of “delegate” to those of us less familiar with things – the actual conceptual meaning of “synthesize” – instead we dust off our old Mavis Beacon typing skills – with some faith that we might imbibe the import of these lessons by all the copy typing we are doing. It is a shame. This looks like a well pitched lesson – doing a very central and useful technique in iphone coding – but there is no higher level explanation – and all these silly code jpegs. Of course I may be wrong. Feel free to point to any peer reviewed educational research which supports copy typing as an effective learning technique.


  • Frank

    Thanks for all your tutorials.

    I have been trying to piece together the UIImage changes that have been referred to by many posts above, but have had no success in implementing them…

    It seems to be a popular problem.


    Any chance of one of you guys who has solved it posting the full code to download?

    I can host it if need be – you can email it to

    Thanks and keep up the good work

  • gope

    Steve, as a former java man, I find these tutorials very helpful. I consider them translation lessons, they have been vital in helping me learn proper objective C syntax. As far as the MVC pattern and upper level concepts go: Apple has excellent explanations of these things in there iTunes U under the iPhone development videos.

    To each his own, I guess.

    Oh ya, Brandon, thank you!

  • gope

    great tut, really helpful, I’ll have to run through it a few more times to really get it all together in my head.

    Quick Question: can we get a simple line or large space between the tutorial names in the tutorial list on the right side of the website, it’s kinda hard to tell them apart b/c the names take up more than one line

  • Cosimoo

    Hello Guys

    I also need help in implementing an UIImageView so that I can show for each Fruit a picture of this fruit. Has someone coded that succesfully? I would be so happy if someone could tell me how to do that.

    I read all the comments in this tutorial and it seems to be a very popular problem, so it would be really helpful if someone tells us the solution.

  • Rohan

    Hi I m unable to get the video of itennis game for interfacebuilder connection. Please help me ………

  • http://blog.raffaeu.com raffaeu

    Hi my name is Raffaeu and I am a NET Microsoft Developer. I want to let you know that your tutorials are really interesting and well done. In this tutorial I was able to understand how to build a: master detail MVC app, use an array to store data, move trough the view and passing info.
    Everything done and compiled in 1 hour!! Compliments, your site rocks! I will write a nice review over my blog, very cool!!

  • Sean

    Thanks for this tutorial! Followed three so far and all great. I made a small typo leaving out a “[” where there should have been two i.e [[ which caused my variables apple, orange, banana not to be recognised at first! Found it after searching back and now this works perfectly.

  • Duane

    Great tutorials! I have run into one problem which seems to have been experienced by others above.

    In Interface Builder when I click on File’s Owner, open the Identity Inspector, select FruitViewController the Outlet area is not filled out automatically.

    Reading through the posts above, I verified that I am using UITextView instead of UIText.

    Here is the entire FruitViewController.h:


    @interface FruitViewController : UIViewController {
    IBOutlet UITextView *fruitDescription;

    @property(nonatomic,retain) IBOutlet UITextView *fruitDescription;


    Any suggestions would be appreciated.

  • Duane

    Sorry the “#import” line above is actually “#import UIKit/UIKit.h”

    I guess the posting code on this page didn’t like the less than and greater than sign.

  • Raghav

    Hi Brandon,

    I am new to iphone.This tutorial is very useful for beginners ..
    Thank you….

  • Bob

    Thanks for a great set of tutorials!

    In your example above I wondered why the Fruit view title+content was set up _after_ it was pushed onto the navigation stack. I’ve seen some apps briefly show old content so I thought it made more sense to set the values first.

    I tried reversing the order in your sample but it doesn’t work – the Lorem ipsum text shows for the first fruit viewed. Alternatively, changing to use animated:NO also seems to cause the same problem. Any idea why?

  • Steve H

    This tutorial was fine regarding navigating among views that are an array of strings. How do you navigate among views that are several xib files or even just .h and .m files? I haven’t seen such a tut yet.


  • JT

    @Steve – the previous tutorial does just that… look at the upper right hand portion of this page and there is a navigation list of tutorials… look for the one called:

    iPhone Programming Tutorial – Transitioning Between Views

  • Drunlar D

    I too had the problem with connecting my IBOutlet and getting an option other than view when trying to make a connection.

    After 2 weeks I discovered I had named my project with a space in the project name and of the sad development error checking on the side of the creators of this SDK that was the issue.

    So if you have a space in the name of your project or project folder remake the project again and don’t add a space.

  • Tudor

    Another excellent Tutorial. Looking forward the others – very clear. Thanks much!!!

  • http://iPhoneSeattle.com Ghenadie

    Great tutorial. Thanks

  • Jay

    For those on XCode 3.2 who are getting frustrated trying to create the fruitDescription Outlet link to the Text View, in 3.2 you have to drag the dot directly to the object itself (as in the actual window that contains the words “Lorem ipsum…” Trying to drag to the object under the inspector window will do nothing.

  • Ike Starnes

    I want to change the textLabel and detailTextLabel of a cell when it has been selected. I’ve tried the following, but no change occurs:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MyAppDelegate *appDelegate = (MyPhoneAppDelegate*)[[UIApplication sharedApplication] delegate]; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.detailTextLabel.text = @”xxxxx”; cell.textLabel.text = @”zzzzz”; [tableView reloadData];}

  • j

    The “Fruits” title & back button did not appear using the current version of xcode.

    Everything else worked.

  • j

    I believe the following should be added after the initialization of the array.

    [apple release];
    [orange release];
    [watermelon release];

  • http://zdavatz.wordpress.com Zeno Davatz

    I followed the tutorial in Xcode 3.1.2 an I can’t get past this error:

    /Users/zdavatz/Documents/xcode/Fruit/Classes/RootViewController.m:14:0 /Users/zdavatz/Documents/xcode/Fruit/Classes/RootViewController.m:14: error: no declaration of property ‘fruitView’ found in the interface

    From the File RootViewController.m

  • Susobhan

    This is very nice tutorial..I want to make a similar kind of application,instead of fruit i have timer,language,voice.
    when i clickd in timer than a picker will come.I have picker class separately.on clicking of timer i want to invoke picker.how can i invoke picker?

  • http://zdavatz.wordpress.com Zeno Davatz

    Ok, works for 3.1.2 as advised. Great tutorial! Thank you and merry X-Mas.

  • Ken

    Thanks for this great effort. It’s very helpful.

    Can anyone explain the advantage of defining the fruit objects and array in the AppDelegate instead of the RootController? I am trying to understand how to best structure larger apps.

  • JO

    How do I get rid of the edit button?

    Thank You

  • schmicko

    Hi Brandon,

    great tutorials here. I’ve been going through them one after the other all weekend.

    Can I suggest a very minor change to this one though.

    In RootViewController.m -> didSelectRowAtIndexPath
    setting the fruitView title and fruitDescription before pushing the new view to the navigation controller.

    I don’t know if anyone has noticed but the view is actually sliding in with the previous title and content and then changing to the new one about half way in.

    Anyway, great work and keep it up. I know I’ll be spending many hours on your site over the next couple of days.

  • jcww33

    Does anyone know how I could add categories?

  • Tom

    Do the “name” and “description” strings in the Fruit class not need to be released because of the “(nonatomic, retain)” bit on them?

    Or is there something else controlling there retain count? Eg.

    Fruit * f = [[Fruit alloc] initWithName@”Apple” description:@”Green/Red/Both”];
    [anArray addObject:f];
    [f release];

    Because we’ve released that “f”, does that mean “anArray” is now controlling the retainCount and we don’t need to worry about a “dealloc” method in the Fruit class itself to release name and description?

    Great tutorial!

  • http://icodeblog.com/2010/02/02/ipad-programming-tutorial-hello-world/ iPad Programming Tutorial – Hello World++ | iCodeBlog

    [...] project will be based on one of my earliest tutorials that displayed a list of fruit in a UITableView and drilled down when they were selected.  We will be expanding on that example [...]

  • http://itunes.com/apps/informa inForma

    Thank you very much for the great example :)
    I created the application “http://itunes.com/apps/informa” with this example

  • http://icodeblog.com/2008/08/08/iphone-programming-tutorial-populating-uitableview-with-an-nsarray/ John

    Thx alot.
    but I still have a question. If I have a human array contains male and female on my first page and when I click on the male array I want somemale’s name like Peter, Tom, John shown on the second screen and when I click on one of those male’s name I can see the a list hobby of individual, can I do that? Is that possible?

  • sam

    Thank you for these tutorials, but if i may suggest something. These tutorials seem to be just getting me to copy and paste code. I think people would better learn if a breakdown of what each line of code does. This is what I have found helps me learn MUCH better on other tutorials. Of course this is my own opinion. Just thought i may suggest.

    Thanks again.

  • Bonnie

    This site would actually be useful if it would:

    1. Stop putting code fragments in tiny/unreadable PNG files… that you have to click on… and you STILL can’t cut/paste or use them. (Just put them in a standard textarea.)

    2. Actually have a PRINT button.


  • VIKI


    Please modify the tutorial by adding pictures to it. Waiting for the next tutorial.

    thanks in advance

  • http://macosxhints.ru Rodion Baskakov

    The best tutorial on UITableView and UINavigationController ever! Thank you very much!

  • fluvly

    Question about importing:

    I saw that Fruit.h has been imported in both RootViewController.m and FruitAppDelegate.m – since FruitAppDelegate has been imported in RootViewController (and viceversa), shouldn’t it be enough to import Fruit.h only in one of those 2 files?

    Thank you for any help! (And thanks for these tutorials, they’re great.)

  • http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/ipad-%e7%bc%96%e7%a8%8b%e6%95%99%e7%a8%8b-hello-world iPhoneGeek 爱疯极客 » iPad 编程教程 – Hello World++

    [...] 此项目将基于使用UITableView显示水果列表教程 。我们将扩展其中一个范例,如下所示: [...]

  • ejaa

    This is such a good tutoriall for beginner and student like me :D

    i got problem when i combine this project with my own project.

    My project seems like this, i created an application with multiviews app. From one of the views, i have some buttons and one button that i want to connect to next view which is as example shown in this example. I copied all codes in FruitsViewAppDelegate into my project AppDelegate, being like this:


    - (void)applicationDidFinishLaunching:(UIApplication *)application{ {

    // Override point for customization after application launch
    [window makeKeyAndVisible];
    FirstViewController *oView =[[FirstViewController alloc] initWithNibName:@”FirstViewController” bundle:nil];
    self.firstView =oView;
    [window addSubview: firstView.view];
    // [window addSubview: nTraining.view];
    [oView release];


    Info *apple = [[Info alloc] initWithName:@”Course Benefit” description:@”The aim of this IPv6 training program is to give in depth information on the transition from IPv4 to IPv6 and expose the participants on the technical expertise needed in the deployment of IPv6 in the organizations network while CNP6 course concentrates in porting IPv4 based applications to IPv6 and writing IPv6 based applications.”];
    Info *orange = [[Info alloc] initWithName:@”Who should attend?” description:@”CNE6 is ideal for network administrators, network support personnel, network designers, networking consultants, IT managers and directors. CNP6 is ideal for network programmers, network designers, networking consultants, IT managers and directors. “];
    Info *watermelon = [[Info alloc] initWithName:@”Training Approach” description:@”Instructor – Led Training: Set in an interactive classroom environment, the instructor will introduce concepts and guide students with detailed explanations and interesting examples to meet the student’s expectation and requirements and at the same time keep the students engaged. Hands – On Lab: Step by step hand – on labs with detailed instructions and guide are provided to reinforce all key concepts. It allows the student to reinforce concepts by performing the tasks they have just learned. “];

    NSMutableArray *fruitArray = [[NSMutableArray alloc] initWithObjects:apple,orange,watermelon,nil];
    self.fruits = fruitArray;
    [fruitArray release];

    // Configure and show the window
    // [window1 addSubview: info.view];

    [window1 addSubview:[navigationController view]];
    [window1 makeKeyAndVisible];}

    all those RootViewController i copied also with Fruit.h.
    The project was sucessful without any errors.
    The window with table is shown, but when i want to click to one of the rows, nothing happened.

    Can u help me :D

  • preeti j

    Nice Tut! Thanx a lot..!!

  • Richard Hakin

    There is a major fault with this code. It does not work. If you key this is exactly the app will crash the simulator. If you download the code and examine it you can see there are extra section in the downloaded code around awakening NIB files that is not in this version and it runs on.

  • Rob

    I got it to work fine. One change: The author names the view “FruitViewController.xib” which I think is misleading since the controller is named the same name. I called it FruitUIView since the view is not a controller.

  • http://u2yauto.ru/ Galtthyboaphozy

    Подбор текстов хороший удачный, помещу сайт в избранное.

  • http://sivasankarmobiledevelopment.wordpress.com/2010/05/25/ipad-programming-tutorial-%e2%80%93-hello-world/ iPad Programming Tutorial – Hello World++ « Sivasankar's Blog

    [...] project will be based on one of my earliest tutorials that displayed a list of fruit in a UITableView and drilled down when they were selected.  We will be expanding on that [...]

  • http://sivasankarmobiledevelopment.wordpress.com/2010/05/25/ipad-programming-tutorial-%e2%80%93-hello-world/ iPad Programming Tutorial – Hello World++ « Sivasankar's Blog

    [...] project will be based on one of my earliest tutorials that displayed a list of fruit in a UITableView and drilled down when they were selected.  We will be expanding on that [...]

  • Valentin

    Will be great if you continue this tutorial with a RSS parse from a XML file…. (maybe a news paper or somthing)

  • http://www.bluelionslair.com Blue Lion


    Thanks for the great tutorial. As someone who hasn’t programmed in years and is just learning object oriented programming on iPhone, your tutorials are the most complete I’ve found. I’m currently about half way through the Apple Dev Intro vids. Great stuff there. Don’t sweat the comments about having to type the code in. Typing the code in does teach two important things. First, you don’t really know the syntax of a language until you have to type it in over and over again. Of course, the basic syntax comes quickly, but thankfully XCode goes a long way in helping avoid unnecessary typing. Second, the fact of the matter is that typing in the code WILL cause several syntax errors that you will get to find when you compile/run. While this may be a pain in the butt, it’s invaluable in your education learning out each part of the system works.

    Thanks again. BTW, I’m glad I’m not the first one to notice you need to release each fruit object you make after you put them together into the array in FruitAppDelegate.m.

    The Blue Lion

  • http://spaceb.org Dids

    Thanks for this great guide!

    I’m running on the latest version of XCode (+ iPhone OS 3.1.3) and ran into some problems.
    I took “description” and sort of cloned it to bring more data in.

    Currently the app crashes when I select a cell, GDB says it’s got something to do with the ‘initWithName:bundle:’, since it can’t find a method like that.

    That particular line is currently: FruitViewController *viewController = [[FruitViewController alloc] initWithName:@”FruitViewController” bundle:[NSBundle mainBundle]];

    Has there been changes that are causing this? Feels like XCode doesn’t know what the “bundle” is, as that wasn’t mentioned in this article.

    Thanks in advance!

  • Ben

    You have a point that it seems misleading, Rob. But the standard way is to define the nib file to be the same as it’s controller. So that you don’t get lost when you have multiple nibs.

  • Roy625@aol.com

    Is it possible to do this from a p-list? If so, will it be a faster running code than making a bunch of controllers and and switching the view of the RootViewController, or wold it be exactly the same, speed-wise? I am hoping displaying a View will be faster than displaying a controllerview. I am writing an app that has a lot of different pages of text to display, but it runs too slow for my liking.

    The code all the way below will switch a View Controller via a p-list by switching the name of the controller in the line of code… rvc.view = viewController.view;
    and adding a new case #… case 1: {
    RootViewController *rvc = [[RootViewController alloc]

    so switching “rvc.view = viewController.view;” to “rvc.view = secondviewController.view;”
    and adding a Case 2 enables you to switch between these two views depending on the users selection

    if([Children count] == 0) {
    NSInteger ViewNumber = [[dictionary objectForKey:@"View"] integerValue];
    switch (ViewNumber) {
    case 1: {
    RootViewController *rvc = [[RootViewController alloc] initWithNibName:@”RootViewController” bundle:[NSBundle mainBundle]];
    //Switch the view here
    rvc.view = viewController.view;
    [self.navigationController pushViewController:rvc animated:YES];
    [rvc release];

  • Rick

    Thanks a lot. Your tutorials are great. I just wanted to mention that you have the
    @synthesize fruitView;
    line in the RootViewController.m file before you add it to the .h file and so causes a build error. I just remmed it out until later when you actually do add the fruitView.

  • Rick

    One more thing. UITableViewCell setText is now depricated and not supported in iOS 4, so you should now use:
    cell.textLabel.text = f.name;

    thanks again…

  • Rick

    I would suggest that you will learn much more if you enter the code, not copying and pasting. You might as well just download the final project and run it, well almost :)

  • Rick

    For some reason, the pictures in the page don’t show up on an iPad, there is just a grey area there. However, you can click on the grey area and the new window does open with the picture. Strange…

  • roger

    what kind of abnormal creates a site about code and put the code as images? amazing… 10 thumbs down!

  • http://appleiphonesoft.com/?p=68 iPad Programming Tutorial – Hello World++ « Apple iPhone app Soft

    [...] project will be based on one of my earliest tutorials that displayed a list of fruit in a UITableView and drilled down when they were selected.  We will be expanding on that example [...]

  • dhanesh

    hey this is very nice code of UITableview in the i phone application i am get very nice knowledge fro this example thanks budy that you can put this example with the all image and also run the application with its output

  • Paul

    Massive thumbs down for the pngs!

  • http://www.ecomsystems.in Gurpreet Singh

    Yes RSS would be an great idea!

  • http://www.ios4jailbreak.com/2010/07/ipad-programming-tutorial-%e2%80%93-hello-world/ iOS4 Jailbreak » iPad Programming Tutorial – Hello World++

    [...] project will be based on one of my earliest tutorials that displayed a list of fruit in a UITableView and drilled down when they were selected.  We will be expanding on that example [...]

  • Alex Thompson

    How do I open this in a new version of Xcode? All I get is “Base SDK Missing”

  • Shiva

    Thanks for this whole iCodeBlog series of tutorials – better than most books!
    I am late to this tutorial and iphone programming…. but better late than never, eh? :-)

    Here is my question:
    I get the code part – the controllers, xibs etc.. and after the last few tutorials and other docs I can generalize the learnings into “rules” such as “if you have a variable, you need to create a @property in the .h file and a @synthesize in the .m file” etc….

    What I am having a hard time grasping is this whole drag and connect in interface builder… Sometimes you drag from the view inspector to File’s owner, sometimes from the actual view to the View box in the Controller window… This drag-and-connect has me a bit confused and I am unable to generalize this in the form of rules I can learn (like above).

    Can you provide some writeup about this? Or point me somewhere which has a lucid description of this? (there might be a tutorial further ahead in your site – if so I just havent gotten to it – if you can point me to that one that will also be great)

    Thanks again!!


  • Greg

    It is really sad when people make demands and they aren’t even being asked to pay for this developer’s service to the developer community. Learn to be just a little humble people.

  • http://codencolors.com/iphone/?p=76 Code 'n' Colors » Blog Archive » iPad Programming Tutorial – Hello World++

    [...] project will be based on one of my earliest tutorials that displayed a list of fruit in a UITableView and drilled down when they were selected.  We will be expanding on that example [...]

  • jeno


    I was wondering if I can put the NSMutableArray in Fruit.m file instead of putting it in the Delegate file? That way I would know what I have in Fruit object.


  • Ben Diaczun

    if you get Base SDK Missing, select the App node in the project window(directly under “Groups & Files”). then in the main menu select File > Get info. In the info window click the Build Tab. Change the Base SDK field to the one you use.

  • Ben Diaczun

    I’ll try to explain drag-and-connect:
    When designing in interface builder, you’re creating a potential object each time you drag something into your UIView. (for example a UITextView like in this tutorial.)
    When you load a Nib file, it creates runtime instances of all the objects. The problem is all the objects don’t have any way to reference them from code. So someone makes a class with all the UIView based objects (we call it a controller (UIViewController based))… such as FruitViewController which has a UITextView* in it.

    now there’s just one more problem…. the big one: how do you make the class you built represent the interface you built?

    the answer is, you tell interface builder who the owner is. (clicking on file’s owner(that’s your controller)) when you select your class in the Identity Inspector for the file’s owner, you’re telling it that your controller is a holder for the UIView based objects.

    the next problem is which objects in your class are loaded with which interface objects?

    that’s where drag-and-connect comes in. You defined IBOutlets in your header. Now, by dragging those IBOutlets(which now appear in Interface builder) directly onto your interface controls you are telling them what your code is referencing.

    So when you call initWithNibName: from your class (inherited from UIViewController) it creates an instance of your class with all your IBOutlets filled in from whatever you dragged them on.

    Note: the “view” IBOutlet is inherited from UIViewController.

    For making apps change when they are upgraded (adding features and removing ads) a single controller class can be initialized with multiple nibs. one for free and one for paid app, without changing and code except the nib name. could also use such techniques to offer selectable button layouts… simply create a new nib for an old program, drag the IBoutlets to new interface elements, and change the nibname loaded in code, the rest of the code would stay identicle. ;p

    i hope any of that helps =)

  • Edgar

    Thank you Rick~ I have much confuse when I follow as IOS4 is little bit different

  • Edgar

    Thank you for the tutorials,
    Although the build was succeeded, I got a blank view with the heading Fruit….(meaning nothing I can choose in row)
    it still have different as I using xcode 3.2.4 in ISO4?

  • Joey


    Great tutorial! Thanks it was a great help.

    I’m using base 4.0 and get the following error in the RootViewController didSelectRowAtIndexPath method.

    Specifically, when I try to access self.fruitView.

    “[RootViewController fruitView]: unrecognized selector sent to instance…”

    Any help would be appreciated.

  • http://www.mobiweb20.com/?p=2384 iPad 编程初步 Hello World++ | 移动互联网2.0|热点|应用|创业

    [...] 此项目将基于使用UITableView显示水果列表教程 。我们将扩展其中一个范例,如下所示: [...]

  • Danny

    I am having the same problem. I also did the sqlite up to the second tutorial but I am not seeing anything.

  • moomy


    You are so unbelievable selfish. Someone has spend time and considerable effort to help the community and there you are being a complete arse. I for one am shocked by your comments. Do you also think a random person should be summonsed to peel your grapes for you???

  • http://www.tour2kerala.tk safil sunny

    Nice Work man….

    Keep Going…

  • Ben

    Really roger? Just type it in man!

  • Cory

    can you please continue with a tutorial on XML parsing integration with this TableView tutorial. I have my XML parser and this tableview app, but i am having trouble combining them to show my xml data in the tableview.
    Thank you very much. great tutorials!!!

  • http://www.digital-canopy.com Brian Kuyath

    I may be a little late on this one (and I sincerely hope you’ve found the solution to your problem already), but the issue you ran into Xcode not knowing what initWithName:@"FruitViewController" bundle:[NSBundle mainBundle]]; is because the name of the function is actually ‘initWithNibName’. :) Code should look like:

    initWithNibName:@"FruitViewController" bundle:[NSBundle mainBundle]];

  • http://twitter.com/Designergianna gianna

    This is a beautiful explanation, with full detail I will make sure to follow the steps given above and implement it as soon as possible, I have read in lots of blogs that I-phone is a very good and most popular application which people are willing to use it more often, also there are lots of applications too