Click here to Skip to main content
Licence CPOL
First Posted 13 May 2010
Views 5,193
Bookmarked 0 times

How To Use The iPhone OS UITableView (Video)

By | 13 May 2010 | Technical Blog
CodeProjectYou see UITableView in all sorts of utility iPhone applications. It is used to display data, lists of items and even to format objects on the touch display. UITableView is one of the things that you can learn that will bring you a ton of leverage in your iPhone app developm
A Technical Blog article. View original blog here.[^]

Post image for How To Use The iPhone OS UITableView (Video)

You see UITableView in all sorts of utility iPhone applications. It is used to display data, lists of items and even to format objects on the touch display. UITableView is one of the things that you can learn that will bring you a ton of leverage in your iPhone app development projects. Today I am going to show you the basics (scroll down to see the video) of using UITableView.

UITableView in iPhone & iPad Programming

UITableView uses the delegation pattern that is very common through iPhone SDK. Generally, the idea is that you will need an object to act of behalf of your UITableView; we will call this object a delegate. When the system needs to know something, like how many rows are in the table, it will simply “ask” the delegate using a specified callback or delegate method.

Delegation is a really useful skill to master and it is used throughout iPhone development. If you need help with delegation and other iPhone SDK design patterns check out these resources that will help you. You may also want to check out the tutorial section on this website.

iPhone SDK 3.2 Must Be Installed

You will need to have iPhone SDK 3.2 installed. Also, before we start make sure to have created a window-based iPhone application.

Step By Step

  • Create Window-based iPhone application
  • Add New UITableViewController Subclass
  • Implement numberOfSectionsInTableView
  • Implement numberOfRowsInSection
  • cellForRowAtIndexPath
  • Import UITableViewController Subclass into your app delegate
  • Create an instance of your UITableViewController Subclass
  • Add your UITableViewController Subclass object to the UIWindow
  • Build and Go

Building UITableView Video

Having trouble seeing the video? Click here to download the mp4 file to your desktop to see the video in your favorite player.

UITableView Source Code

#import "TableViewOne.h"

@implementation TableViewOne

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return 5;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(
    NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = 
            [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = [NSString stringWithFormat:@"%i", indexPath.row];

    return cell;
}

@end

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

MobileAppMastery



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 13 May 2010
Article Copyright 2010 by MobileAppMastery
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid