iPhone SDK: Working with the UITableView Class – Part 2

iPhone SDK: Working with the UITableView Class – Part 2

Tutorial Details
  • Technology: iPhone SDK 3.2 - 4
  • Difficulty: Beginner
  • Completion Time: 30 Minutes

Welcome to the second part of our series on using the UITableView class! In this tutorial, we will cover how to add details to a UITableViewCell class, more UITableViewDelegate methods, and lazy loading of table view rows. We will also customize the appearance of the table view using cell.textLabel.text, cell.imageView.image, cell.accessoryType, cell.detailTextLabel.text, and custom section header/footer text. These enhancements will make our UITableView class more aesthetically appealing while still sticking to the iPhone Human Interface Guidelines required by Apple.

Table Cell Display Properties:

  • cell.textLabel.text: This property controls the main text label displayed in each table cell.
  • cell.imageView.image: This property will set a custom UIImage to the left of the textLabel.
  • cell.accessoryType: This property will set a default disclosure icon, such as a checkmark or blue arrow, to the right of the textLabel.
  • cell.detailTextLabel.text This property will set a second row of slightly smaller text underneath the textLabel.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://bcproducties.com/ BCProducties

    Would it be possible to make the source files available for download?

    • http://mobile.tutsplus.com Mark Hammonds

      Just added a download link above.

  • Martin Jones

    Hey! Great Tutorial very well explained and easy to understand! Fantastic!

    If I wanted to show another table view after I tapped the first table view i.e it went into another screen with a set of information on it, rather than have a pop up alert – can you show how to do this????

    • http://twitter.com/patelaxit Axit Patel

      Hey Martin,

      What you are talking about is using the UINavigationController, which is a whole different story. If other readers would like to learn the same I will create another tutorial on using the navigation controllers.

      Regards,
      Axit

      • James

        Thanks for this.I would definately be interested in a tutorial on navigation controllers

      • Vasilis

        Great tutorial,keep the good work!I think that it will be awsome to create another tutorial to combine table view with navigation controllers!Both part1 and part2 were great and and very good explained,thank you Atix…
        Sorry for my English…

    • Axit Patel

      Since many people have requested, I have started on creating a tutorial on using UINavigationControllers. Should be up in about 2 weeks or so. :)

  • Martin Jones

    Hello again , just downloaded the source files and I get this error message when trying to ‘Build and Run’

    error: There is no SDK with the name or path ‘iphoneos4.0′

    What does this mean and how do I fix it?

    Any idea?

    • http://i.cbeninati.com C. A. Beninati

      Hey Martin, that error comes from having an older version of the SDK installed. Have you downloaded the latest SDK?

    • http://twitter.com/patelaxit Axit Patel

      Hey Martin,

      I agree with the other comment. Its because you might be still running the old version of the iPhone SDK. I forgot to mention that this tutorial was made using the IOS 4.0 SDK. Hope this helps. :)

  • http://cligs.com Egze

    Loved the tutorial! You explain everything very well. Keep it up please!

  • http://www.benpalmer.info Ben Palmer

    Brilliant tutorial Axit, i would love to see a UINavigationController tutorial. Also linking up with a SQL Lite database would also be very helpful.

    • Ignacio

      Yeah! with connection to SQL lite also be very nice!.

      • http://www.benchic.com Ben

        Yes! That would be very useful

  • Yang Fan

    This is the most useful wedsite i have finded. Thanks for yours sharing.

  • http://mobile.tutsplus.com vishal

    Excellent tutorial Axit. Looking forward to your UINavController tutorial.

    Speaking of the same, I wanted to offer a small suggestion:

    Most of the tutorials I have seen so far show this sort of structure:
    1. A UITableView with multiple rows
    2. Clicking on a row takes you to another (detail) view with either a label or a text area that displays the name of the row you clicked on.

    It would be nice to see how one could incorporate different/unique content in the detail view for each row rather than just the name, as I suspect that is what most people want to know how to do :)

    Your tutorials are much appreciated by us new iPhone developers!

    • http://twitter.com/patelaxit Axit Patel

      Vishal,

      I completely agree with you that most of the tutorials follow the same structure. I understand what you want to know but since most of the readers want to learn the very basics, I have made the tutorial that shows a different image and description for each tableview row. Here’s the link to the tutorial: http://bit.ly/9wzr7O. Let me know in the comments of the tutorial what you think about it.

  • Dan

    Great Tutorial!
    I got two questions:
    1) In order to fill the imagesArray you create a couple of UIImageViews, but you don’t release them later. Is this okay or did you just forget to do it?
    2) Why do you create the dummy arrays anyway? Couldn’t you just say
    self.sitesArray = [[NSArray alloc] initWithObjects:@”..”, … , nil]; ?
    Or is there a reason to do it the way you did?

    Thank you very much.

    • http://mobile.tutsplus.com Mark Hammonds

      Hi Dan,

      Great questions! I actually chose to answer them in Q&A session 3. You can find that video response here:

      http://bit.ly/aRNMLu

      Hope the answer is helpful to you.

      Best Regards,
      Mark Hammonds

  • http://www.ignacioopazo.com Ignacio

    Hello! I’m from chile and all the tutorials are excellent!

    About this, I add the method “accessoryButtonTappedForRowWithIndexPath” because I miss this button to open the url of each page.

    Instantiate the object “UiApplication” and it worked perfectly with the function “opernUrl.”

    Thanks and keep so!

  • Hitog

    Hi, Great tutorial!! Very helpful!
    Thank you so much for making the tutorial.

    Btw, can you please make a tutorial on how to upload text file into tableView ? And one can choose what text file he wants to see in the tableview?

  • http://birdfilms.com Judy Fieth

    EXCELLENT AXIL! Thank you very much for this tutorial, especially for “-t” and #pragma mark.

  • Aj

    This was a wonderful tutorial! What I really like about your teaching style is that when you make any new changes, you run your code to show the changes! I hope you get the chance to make a tutorial on CoreData and UITableViews.

  • Michael

    Still waiting on the other Tutorial :(

  • Pat

    Axit, terrific set of tutorials, thanks for doing these. Would welcome more, they are really informative, rare to find such good quality info.

  • http://www.andreipotorac.com Andrei Potorac

    Although it’s a bit sloppy, it’s a great tutorial, because the best thing we can see is an iOS coder at work! So… more like this please! :-)

    I learned new stuff that I didn’t find in lots of other tutorials! (on Apple, Stanford and some books)

  • Suhail Larik

    Hi!
    Really wonderful and helpful tutorial.
    I appreciate u a lot.

    Thanks Axit Patel…

  • http://techwonders.blogspot.com Tan

    Thanks Axit Patel.

    This is really a wonderful tutorial on tableview on a view based app. I have been searching high and low but the rest of the other tutorials are using window based app with navigational controller etc.

    Cheers to you.

  • http://greti.com rgreti

    Can you show us how to “How to add a nice Background Image to a Grouped Table View” and that does not display broken artifacts around the table cells? Similarly, “How to add a Background Image to the Navigation Bar”?

  • http://yepdev.com Leonardo Frangelli

    Just thank u!

    It helps me a lot.

  • SAleh

    Many thanks……

  • Gislene

    Hi! I’ve been watching your classes and have been learning a lot. Thank you so much!

  • Charged Neuron

    Thank you so very much. Your tutorial accomplished in less than an hour what I have been spending weeks trying to figure out. Whew!

  • theprof

    bravo! Excellent work thank you very much

  • Steiny

    Great tutorial. I’ve got about 8 hours experience under my belts at the end of this, have two views working and splash screen! :-)
    Now… time to track down that UINavigation tutorial! :-D

    Thanks for taking the time to show us noobs how its done…

  • adel

    i just want to say .. this is great, good demo. keep it on