This is part of an ELC Tech Network

iPhone Programming Tutorial – Creating a ToDo List Using SQLite Part 2

This tutorial is part 2 in our series of creating a to-do list.  I will assume that you have completed the following tutorial and its prequisites.

I will be using the code produced from that tutorial as a base for this one.  When you are finished with this tutorial, your application will look something like this:

In this section, I will not only teach you how to display the SQL data in UITablewView, but I will be detailing how to display it in multiple columns with images and text.  For this tutorial, you will need to download the following images.

We will be using these images to denote the priority (Green = low, Yellow = medium, Red = high).

Bring Your Code Up To Speed

Before we begin, we need to add some code to the Todo.h and Todo.m class to support the priority field in the database.  Open up Todo.h and add the following code:

All that is new here is the added NSInteger priority property.  We will be using this to get and set the priority for a given todo object.  Next, open Todo.m and add the following code.

The first line that has changed is the synthesize line.  We added our priority property to allow XCode to create the getter and setter methods for it.  Next, you will notice that the sql statement has changed slightly.  We are now getting the priority in addition to the text from the todo table.  Finally,  we set self.priority property to the selected priority value from the todo table.  This is done by using the sqlite3_column_int method.  We pass the init_statement and the number 1.  1 being the index of the sql array for which the priority data is contained.

Add Images to Your Project

Download the images above and save them to your project directory.  Inside of your project, right click (control-click) on the Resources folder and click Add -> Existing Files… Browser for the images, select all of them and click Add. Check the box that sais “Copy items into destination group’s folder (if needed)”.  Click Add. The image files should now appear inside of your Resources folder.

Create a UITableViewCell Subclass

To display data in columns within a UITableView, we have to create our own cell class that defines the type of data we want to display.  By default, Apple provides us with a simple cell object that can only display one column of text.  Normally, this is fine as it will work for a wide variety of applications.  Since we require 3 columns for this tutorial, we need to wrap our own cell object.

Click File -> New File… and select UITableViewCell. Click Next.

Name this file TodoCell and make sure this that the box that sais “Also create TodoCell.h” is checked.

This will create a “barebones” UITableViewCell object with some basic methods already filled out.  Let’s add some properties to this class.  Open up TodoCell.h and add the following code.

Let’s take this line by line…

First, we see a Todo object being declared.  Each cell will know which Todo item is associated with it.  This will help out when updating the data in each cell.  Next, we see 2 UILabels and a UIImageView.  To understand why these components are needed, here is a screenshot of how each cell will look.

We see the “Green Dot” which is an image being rendered by a UIImageView.  The word “low” and “Take out the trash” are both UILabels. After they are declared, we simply create them as properties.  Notice that we are NOT creating a property for the Todo object. We will not be synthesizing it either. This is because we want this variable to be private.  Setting this variable requires some additional code so we don’t want any code writer to simply be able to say cell.todo = foo;  You will see why this is so further on in this tutorial.

Below this are some method declarations.  First we see the method “imageForPriority”.  We will be using this method to decide which image (green, red, yellow) gets displayed for a given priority.  Next, we see the “getter and setter” methods for the todo object.  As I explained above, the setter will contain additonal code besides assigning the todo object.

Now open up TodoCell.m.  We will be writing quite a bit of code in here so I will break it up the best I can.  First, add the following code to create some of the initialization:

Ok, some new stuff here.  First, we see 3 static UIImages.  These will hold reference to each of the three images (red, green, yellow).  Since we only need to allocate them once, we make them static.  Static means that they will be associated with the class not the instance.  So we can make as many TodoCells as we want but only 3 UIImages will be created.  On the next line there is a private interface.  This allows us to declare a private method that no one else can use except this class.  Following this is the synthesize line.  Notice again that we are NOT synthesizing the todo object.

Looking at the initialize method…  All that is going on here is we are intanciating each of our UIImages with the correct image for a given priority.  This initialize method will get called once when the first instance of the todocell class is built.  Moving on… Add the following code: (Note: it might be small and hard to read.  If this is the case, click on the image to open it and the text will be full size)

This is the initialiazation method for any UITableViewCell.  First, we need to call the super classe’s (UITableViewCell) initWithFrame to ensure that the underlying components of the cell get set up properly.  Next, we get a reference to the contentView.  The contentView is the view for each cell.  We will be adding all of our UI components to this view.

The next 3 lines initialize a UIImageView and add it to our view.  Notice that we are populating it with the priority1Image.  This will just be a dummy placeholder until we update it.

Advertisement

Following this, we initialize the todoTextLabel.  This label will display what it is we need “to do” such as “Take out the trash”.  There is a method that we will be calling called “newLabelWithPrimaryColor”.  This is a method I will detail a little further down.  What it will do is build a new label with the attributes that we specify when we call it.  This method was taken directly from Apple’s “Seismic XML” sample code.  It’s pretty handy.  After this gets called, we simply add the new label to our view and these steps get repeated for the todoPriorityLabel.

Finally, the method “bringSubviewToFront” is called on the priority UIImageView.  This method is used in case there is text that gets near the image.  It will cause the image to appear above the text.  You can use this for layering your UI components.

Still with me?  Good… now let’s add the following “getter” and “setter” methods for the todo object.

The first method todo is simple.  All it does is return our todo object.  The setTodo is a little more involved…

First, we set the incoming (newTodo) to our classe’s todo object.  Next, we update the UITextLabel so we can display the detailed todo information.  Following this we set the image of our UIImageView by calling the method imageforPriority.  I will detail this method further down in this tutorial but all it does is return an image for a given priority.  Last, we have a switch statement.  The syntax of a switch statement is the same in objective C as it is in most languages.  If you don’t know what a switch statement is Google it.  Based on the priority of the newTodo, the priority label gets updated with one of three words (High, Medium, Low).  The [self setNeedsDisplay] tells the cell to redisplay itself after this todo has been set.

Now, let’s add the code that lays out the cell.

This method gets called automatically when a UITableViewCell is being displayed.  It tells the UITableView how to display your cell.  The define statements are similar to define statements in C.  The reason we are coding like this is because we can tweak these variables to get the display to our liking.  First, we call the layoutSubviews of the super class.  Next, we get a reference to the contentView.bounds.  This variable will allow us to figure out how much drawing area we have and allow us to line objects up properly.

The if(!self.editing) part is not neccessary but is good practice.  You would use this if you allowed editing of your cells.  This code is a little tough to explain by typing, but I will do the best that I can.  First, we declare our right-most column.  This is done by making a frame to hold the content.  This column will hold the text of the todo item.  Most of the code here is just positioning.  You can play with these numbers and see how it moves stuff around.  Once all of the positioning code is completed, the frame of our todoTextLabel gets set to this newly created frame.  This is done for each of our UI components.  You can lay them out however you like, as I may not have the best layout.

We have one more method to override.  It’s the setSelected method.  Go ahead and add the following code.

This method gets called when the user taps on a given cell.  We need to tell the cell how to behave when it gets tapped on.  This method should look pretty straight forward.  First, we call the setSelected method of the super class.  Next, we update the background color depending on whether or not the cell was selected.  Finally, the labels get set to a white color if the cell gets selected.  This is to contrast the blue color that the background becomes when the cell is selected.

This last 2 methods that I want to talk about are the helper methods that we used earlier in the code.  Add the following methods to your code.

newLabelWithPrimaryColor

This method got called when we were initializing our UILabels.  It takes a few parameters that should be pretty self explanatory.  Looking through the code, we first see the font being initialized with the size that we specified.  If bold was specified this is also accounted for.  Next, we instantiate a new UILabel and give it some properties.  Finally, this newly created UILabel gets returned.

imageForPriority

This method is actually quite simple.  It simply takes a priority and returns the UIImage that is associated with that priority.  Notice the default clause.  I decided to handle it like this instead of doing “case 1″ to handle all other cases.  For whatever reason, if there is ever a priority that is not 1,2 or 3 it will, by default, have low priority.

Now that we have created our UITableViewCell, we need to display it in the table.  Open up RootViewController.m and add the following import statement.  This will allow us to use our TodoCell object.

Now find the numberOfRowsInSection method and add the following code

I’m not going to really go over this, as this is almost the exact same code as in the Fruits example.  Basically, we are returning the number of todo items.

Now for the magic…We will now add our TodoCell to allow it to be displayed.  Find the cellForRowAtIndexPath method and add the following code.

This code is fairly similar to the default code that Apple has provided us.  The first change is we are instantiating our TodoCell object.  We are creating it with the initWithFrame method and passing our identifier to it.  Next, we get reference to the application’s appDelegate and use it to look up the todo item at the given index.  This should be familiar.  Finally, we set the todo item of the cell to the todo item at the row index and return the cell.  That’s it! Go ahead and click the Build and Go icon and see your todo list come to life.  Here is a screenshot of what your app should look like.

That concludes part 2 of this tutorial. Join me next time as I show you how to display detailed todo info using some new UI controls that we haven’t seen yet. As always, post your questions and comments in the comments section of the blog. Download The Sample Code

Happy iCoding!

This entry was posted in SQLite, iPhone Programming Tutorials and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

93 Comments

  1. Posted February 12, 2009 at 5:36 pm | Permalink

    Hi Brandon,

    Your example worked fine. But,I am trying to crate a to-do list with 5 items instead of 3.

    When I debug the line

    if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK)

    it doesn’t get inside the code block under “If” statement.

    Can you show me some light?

    Redwan

  2. Posted February 12, 2009 at 5:39 pm | Permalink

    Brandon,

    The file was todoAppDelegate.m file.

    Redwan

  3. Posted February 18, 2009 at 6:49 am | Permalink

    Hi Brandon,
    Very nice tutorials.
    I am very new….
    I have the same code as you have said…
    Its compiling good
    but in the simulator data is not appearing
    Please could you help me to fix it.
    What i should do to get the data in the simulator

    thanks in advance
    bye
    kavita

  4. Posted February 18, 2009 at 6:50 am | Permalink

    sorry my mail address is wrong it is adjusted again

    bye
    kavita

  5. wiegeabo
    Posted February 22, 2009 at 5:08 pm | Permalink

    Brandon,

    Great tutorials. I’ve got the todo app running, but no images are showing up. Just the data. And I haven’t found any differences with my code. Any ideas?

  6. wiegeabo
    Posted February 22, 2009 at 5:12 pm | Permalink

    @kavita

    I has the same problem. Then I noticed that I had named the function layoutSubview instead of layoutSubviews.

  7. Posted February 23, 2009 at 2:42 pm | Permalink

    When I try to run the supplied sample code, my simulator crashes while Xcode displays this message:

    “TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION”

    It looks like others have had this problem. Any ideas?

    Thanks.

  8. Posted February 23, 2009 at 4:33 pm | Permalink

    I’m a little disturbed by your private interfaces. I’m just learning Objective-C and I thought private methods could just be declared in the header file but in a @private section. Am I right to assume that it has the same effect as your private interfaces, without hiding those methods from people importing header files?

  9. maxfiresolutions
    Posted March 15, 2009 at 1:34 am | Permalink

    Hi,

    These are really great tutorials for first timers like me to MAC and iphone development in particular. Bravo!

    I just want to ask one question…. which is off course silly. Why havnt you declared @ property (nonatomic, retain) sqlite3 *database or something similar in the todo.h file.

  10. LakshmiKanth Reddy
    Posted April 8, 2009 at 6:01 am | Permalink

    Hi Brandon,

    You are really doing a superb job, which cannot be expressed, with your work many people like me are able to gain the knowledge, here i have one query :

    if i want to create an application where the horizontal and vertical scrolling of the application has to be done based on the device movement, ie., if we move the device to left then it has to do the left horizontal scrolling and if towards right then right horizontal scrolling and same for top and bottom .

    ie., we have to do the coding based upon the system events, can u help me out in doing this.

    if anybody can help me out in this then it would be greatly appreciable.

    Thank you .

  11. Wilbert
    Posted April 28, 2009 at 1:03 am | Permalink

    Hi,
    Your tutorials are very helpful. I’m new into iphone programming and having found your site was very useful in my development.

    I followed your todo example but modified it a bit, instead of using an sql to retrieve the data, i used an array just like in the fruits example. however, im am getting an error “_TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___”. Also, there’s a warning on the property for the three todoCell data (todoTextLabel..), “requires method setTodoTextLabel to be defined – use @synthesize, @dynamic or provide a method” though I synthesize it as describe in your tutorial.

    Could you please provide me some code on how to do this using array instead of accessing the database?

    thanks,
    Wilbert

  12. Posted April 29, 2009 at 6:50 pm | Permalink

    My source compiles with no errors, warnings, etc; however, when it compiles I am left with a blank UITableView as was ‘rksaraf’. Any incite on this issue? I double checked my code and it seems to all be correct. The only thing I did was change a few things as I am trying to create a Task Manager app that will eventually call a database via server, populate the UITableView, then allow for responses back to the host server; however, if I can’t get this working I guess I’m S.O.L. Could someone please assist me on this issue?

  13. Ben
    Posted June 22, 2009 at 5:51 pm | Permalink

    if you are getting the error:
    “_TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION__” (or your app just quits and there is a popup asking you to report it)
    replace
    “self.text = [NSString stringWithUTF8String:(char *)sqlite3_column_int(init_statement, 0)];” in Todo.m with
    “char *pointer = (void *)sqlite3_column_int(init_statement, 0);
    if (pointer == NULL)
    self.text = nil;
    else
    self.text = [NSString stringWithUTF8String: pointer];”

  14. Calgman
    Posted June 26, 2009 at 3:07 pm | Permalink

    Hi – This is a great tutorial for us beginners. Thank you very much for taking time to develop this series.

    I like to work thru problems. Having said that, I approached this tutorial w/ a twist of using my own variables rather than what the tutorial used – that way, I have to work to fix the compile/run-time errors.

    I called the database sql_todo.sqlite, but used the same table name as in the tutorial (todo) when populating it; but in the code I used sql_todo for the “select” statement. Because of this, no data was shown in the simulator. After I fixed the code, the simulator shows data – but the format is not what the tutorial shows.

    1. The priority label is on the right side (over-writes the text of the to-do list)
    2. The priority images are not shown at all.

    I have checked the code and the #defines in the layoutSubviews() method. I am still scratching my head.

    Any pinters? Thx in advance!
    Calgman

  15. Anurag
    Posted July 22, 2009 at 1:53 pm | Permalink

    @rksaraf I had the same problem with only the priority images showing up. I named the function wrong. It was supposed to be “layoutSubviews” but I called it “layoutSubViews” with a caps V. I’m so glad that things are case-sensitive in Obj-C :)

    Thanks for the awesome tutorial Brandon.

  16. garyZ
    Posted July 26, 2009 at 7:12 pm | Permalink

    Thanks for the SQL parts of the tutorial. I have used it to load tables and store information when I start using handleOpenURL. I didn’t create the project as a Navigation Controller and had to add the RootViewController class and the RootViewController.xib. Using your example to set the IB outlets I believe I have them setup correctly. However the screen displays only “Root View Controller” at the top and an empty window. Is there anything I might be missing in the Interface Builder.

  17. garyZ
    Posted July 28, 2009 at 9:56 am | Permalink

    Brandon,

    I want to thank you again for these wonderful tutorials. After much pain and time attempting to add a navigation controller to my existing project I decided to start with a new project and one of your earlier tutorials. I will then add my existing code to it. Once again thanks as I have read many of Apple’s sample projects and it is your screen shots and how to use Xcode and Interface Builder that makes any of their code useful.

    Gary

  18. Claijon
    Posted August 4, 2009 at 1:50 pm | Permalink

    Who am I? Where am I?
    totally lost…

  19. Kl
    Posted September 17, 2009 at 7:20 pm | Permalink

    Hi Brandon,

    I have a “_TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION_” error when it reaches the line ” [cell setTodo:td]; ”
    not sure what is wrong.

    Thanks,
    KL

  20. mora
    Posted September 21, 2009 at 1:39 pm | Permalink
  21. Posted September 26, 2009 at 1:07 pm | Permalink

    Could you update it to SDK 3 ? I got problems at the “magic” at the to last step (cellForRowAtIndexpath & numberOfRowsInSection) since of the new naming of appdelegates, tried to go through the apple provided book exmaple, but that didn’t work.
    Great tutorial btw :)

  22. Robert
    Posted October 2, 2009 at 1:58 am | Permalink

    I had to add #import “todoAppDelegate.h” to the RootViewController.m to get it to compile and that just doesn’t seem right to me.

    Am I missing something?

  23. Posted November 22, 2009 at 7:03 am | Permalink

    I’m also getting the uncaught exception issue. The problem appears (for me) when the sqlite3_prepare_v2 call is made in the initialiseDatabase call in TodoAppDelegate.m. I added an extra check for the result of the call and logged an assert with the message reported from SQLite. The message is “library routine called out of sequence”.

    If I run your sample code, it works no problems. So my guess is it’s something to do with the SDK version of either the iPhone or SQLite. I checked the reference for SQLite, and we’re both pointing to libsqlite3.0.dylib.

    When I highlight the library reference and click the info button in the toolbar, I see that your library path is the same as mine (usr/lib/sqlite3.0.dylib), but the full path is different. Your path is rooted in my downloads directory under the downloaded project directory name, then iphoneos2.0/usr/lib/sqlite3.0.dylib, and mine is rooted in developer/platforms/iphoneos.platform/developersdks/iphoneos3.1.2.sdk/usr/lib/libsqlite3.0.dylib.

    I have the downloaded code set to compile against simulator 3.1.2; the same as my follow-along project, however the reference appears to be against a different version of the library. I would expect if we’re compiling against the same version of the SQLite library, that the API wouldn’t have changed, but that’s the only thing I can thing of – that there’s a missing call before the prepare in the version of the library I’m working against?

    I’m new to the Mac, and iPhone programming. I hope this can be useful to yourself or one of your readers. I’ll keep digging in the meantime, and post if I find an answer first.

    Thanks for the great tutorials. They’re easy to follow and quite informative.

  24. Posted December 1, 2009 at 6:51 am | Permalink

    @Robert

    I had the same problem, Txs for the solution. I got the next error in RootViewController.m

    Error: todoAppDelegate undeclared (first use in this function)
    error: appDelegate undeclared(first use in this function)
    error: expected expression before ) token

    with Finally, the method it was solved:)

  25. IISword
    Posted December 7, 2009 at 8:08 am | Permalink

    Yo I couldn’t get the program to initialize the three images in the beginning without calling the method in one of my other cell. Any ideas on what happened? (and yes I did use a +)

  26. IISword
    Posted December 7, 2009 at 8:10 am | Permalink

    nvm I didn’t spell initialize right

  27. Posted December 22, 2009 at 3:04 pm | Permalink

    Your post is an inspiration for me to discover more about this topic. I must concede your lucidity expanded my sentiments and I will forthwith grab your rss feed to remain up to date on any succeeding articles you might write. You are due, thanks for a job well done!

  28. Posted December 23, 2009 at 3:14 am | Permalink

    My code compiles but then crashes after install on the iPhone-Simulator. That must be a memory leak but how do I find that memory leak?

    I also get No -’initWithPrimaryKey:database:’ method found.

    But as said: it still compiles and installs. Then it just crashes on the Simulator.

  29. Posted December 23, 2009 at 3:36 am | Permalink

    Ok, this is what GDB tells me:

    Attaching to process 10936.
    2009-12-23 10:32:39.211 todo[10936:207] *** +[UIFont boldSystemFontOfSize]: unrecognized selector sent to class 0x16927e0
    2009-12-23 10:32:39.213 todo[10936:207] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** +[UIFont boldSystemFontOfSize]: unrecognized selector sent to class 0x16927e0′
    2009-12-23 10:32:39.214 todo[10936:207] Stack: (

    I am on Xcode 3.2.1

  30. Posted December 23, 2009 at 3:39 am | Permalink

    Ok, was missing the :fontSize in

    UIFont boldSystemFontOfSize:fontSize

    Console Debugging is very useful!

  31. Posted December 23, 2009 at 4:54 am | Permalink

    See: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewCell_Class/DeprecationAppendix/AppendixADeprecatedAPI.html

    initWithFrame:reuseIdentifier:

    Initializes and returns a table cell object. (Deprecated in iPhone OS 3.0. Use initWithStyle:reuseIdentifier: instead.)

    That is in file TodoCell.m:32

    How do I need to change that?

  32. Posted December 23, 2009 at 8:11 am | Permalink

    Ok, above is not necessary. I mixed up

    todoPriorityLabel

    with

    todoTextLabel

  33. Kevin
    Posted January 2, 2010 at 12:35 am | Permalink

    In TodoCell.h in your solution I am getting three errors:

    The errors are:
    error: expected specifier-qualifier-list before ‘Todo’ (line 13: Todo *todo;)
    error: expected ‘)’ before ‘Todo’ (line 25: -(Todo *)todo;)
    error: expected ‘)’ before ‘Todo’ (line 26: -(void)setTodo:(Todo *)newTodo;)

    Can anyone help? I am using the code sample code from this site, so I don’t understand what could be wrong. Thanks

  34. Posted January 15, 2010 at 10:09 am | Permalink

    Hi Brandom,

    I’ve been following your tutorials and all have been really useful. Thanks a lot for sharing them.

    I’m having issues with this particular one: has no errors but doesn’t display anything…

    I download then your code. I run it and… same thing.

    Have you got any idea what is this happening?

    Thanks in advance.

  35. MIke
    Posted January 21, 2010 at 5:06 pm | Permalink

    I have same problem with Silvia

  36. MIke
    Posted January 23, 2010 at 5:16 pm | Permalink

    I finde why there is empty list, for some reason by me, the database path have to user absolute path. That means in file: todoAppDeleagate.m and funcion name: initialzeDatabase, you have to difine your database path.

    Yes, NSLog() will help you. for using that, you have to write

    #define DEBUG

    after import part by file todoAppDelegate.h

    Hope my infomation could help somebody.

  37. Campbell
    Posted February 20, 2010 at 7:10 am | Permalink

    Hey great tutorials.

    I’m getting a compile error in RootViewController.m – “TodoCell” undeclared.

    Everything compiled just fine until this point.

    “Todo.h” and “TodoCell.h” have both been included.

    Any thoughts?

  38. Campbell
    Posted February 20, 2010 at 7:13 am | Permalink

    Never mind found it. I named the class ToDoCell.

    You always find your errors after you ask the question.

  39. pithhelmet
    Posted February 27, 2010 at 10:56 am | Permalink

    Hi Brandon….

    Three questions -

    1) How do I add a login page to be first page displayed on this application? Just a simple view with a graphic, a text entry field and a button. The button click will bring up the tutorial entry point?

    2) When the item list is first displayed, the icons and priority are correct (as in database) but when I look at item, change priority, then return to item list, the icons for the priority are all green dots?

    3) When I deploy the application to my iTouch, if i leave the debug code section in, the app works… if I set it to release, the app will not show the detail view of the data.

    Thanks for a fantastic tutorial!!

    take care
    tony

  40. pithhelmet
    Posted February 27, 2010 at 10:58 am | Permalink

    One additional question….

    the update status button text does not change when clicked. I know the event is being fired because the text in the status text line does indicate the proper values, just the toggling of the button text does not work….

    any ideas?

  41. Ham
    Posted June 22, 2010 at 4:01 pm | Permalink

    Great tutorials. Couple notes for Xcode 3.2.2 users…
    RootViewController.m should end up with the following imports. The part 1 and 2 tutorials do not explicitly say to add all of these, and for me at least, Xcode did not auto add them, but they are present in the downloadable sample code.

    #import "RootViewController.h"
    #import "todoAppDelegate.h"
    #import "Todo.h"
    #import "TodoCell.h"

    Adding these resolved “appDelegate undeclared” errors.

    Also in TodoCell.m, “initWithFrame” is deprecated. The following update worked for me…

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    // Initialization code

    UIView *myContentView = self.contentView;

    self.todoPriorityImageView = [[UIImageView alloc] initWithImage:priority1Image];
    [myContentView addSubview:self.todoPriorityImageView];
    [self.todoPriorityImageView release];

    self.todoTextLabel = [self newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:14.0 bold:YES];
    self.todoTextLabel.textAlignment = UITextAlignmentLeft; // default
    [myContentView addSubview:self.todoTextLabel];
    [self.todoTextLabel release];

    self.todoPriorityLabel = [self newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:10.0 bold:YES];
    self.todoPriorityLabel.textAlignment = UITextAlignmentRight; // default
    [myContentView addSubview:self.todoPriorityLabel];
    [self.todoPriorityLabel release];

    // Position the todoPriorityImageView above all of the other views so
    // it's not obscured. It's a transparent image, so any views
    // that overlap it will be visible.
    [myContentView bringSubviewToFront:self.todoPriorityImageView];
    }
    return self;
    }

  42. Chaz
    Posted June 28, 2010 at 7:24 pm | Permalink

    Ham,
    Thanks for providing the updates. I was able to get it to build with no data showing, but once I updated with the code you provided everything loaded successfuly

  43. Simon
    Posted July 31, 2010 at 3:59 pm | Permalink

    Hi, I follow your tutorial very carefully, and my app doesn’t open… When I put this code in comment
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    testAppDelegate *appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate];
    return appDelegate.todos.count;
    }
    my app open but nothing is show.

    Anybody have an idea?

4 Trackbacks

  1. [...] iPhone Programming Tutorial – Creating a ToDo List Using SQLite Part 2 [...]

  2. [...] a ToDo List Using SQLite – Part 1 -Part 2 – Part [...]

  3. [...] 49. TodoList sqlite 2 [...]

  4. By Anonymous on June 24, 2010 at 3:33 pm

    [...] [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">