Tutorial details

Creating A Table View | App Code for Sale | Preview

Creating A Table View | iOS Tutorial

How to create a simple table view

Overview PAGE TOP

Reference: http://www.geekylemon.com/WEBPROTECT-xcodetableview.htm

In this tutorial i will be showing you how to create a simple table view

Features:

  • 1 label
  • 2 views
  • navigation based app

tables view are great for displaying , adding and removing content. tables views is most used in your ipod allowing you to enter a detailed view to play music.

ViewController.h PAGE TOP

@interface ViewController :UIViewController {
@class Detailviewcontroller;
@interface RootViewController : UITableViewController {
NSArray *contentArray;
Detailviewcontroller *dvController;
}
@property (nonatomic, retain) Detailviewcontroller *dvController;
@end

ViewController.m PAGE TOP

#import "AppDelegate.h"
@implementation ViewController
- (void)viewDidLoad
{
contentArray = [[NSArrayarrayWithObjects:
@"one",
@"two",
@"three",nil]retain];
    [super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//return 0;
return [contentArray count];
}
// 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:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];
    }
// Configure the cell.
    cell.text = [contentArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath
{
if (dvController == nil) {
Detailviewcontroller *aController =
[[Detailviewcontroller alloc]initWithNibName:@"DetailView" bundle:nil];
self.dvController = aController;
        [aController release];
    }
    [dvController updateRowNumber:indexPath.row];
    [[self navigationController] pushViewController:dvController animated:YES];
}
- (void)viewDidLoad
{
message.text = [NSString stringWithFormat:@"row %i was clicked",rowNumber];
    [super viewDidLoad];
}
- (void)dealloc
{
    [dvController release];
    [super dealloc];
}
@end

DetailViewController.h PAGE TOP

@interface DetailViewController :UIViewController {
int rowNumber;
IBOutlet UILabel *message;
}
@property(readwrite)int rowNumber;
@property (nonatomic, retain) IBOutlet UILabel *message;
Detailviewcontoller.m
@synthesize message, rowNumber;
rootviewcontoller.h
@class Detailviewcontroller;
@interface RootViewController : UITableViewController {
NSArray *contentArray;
Detailviewcontroller *dvController;
}
@property (nonatomic, retain) Detailviewcontroller *dvController;
-(void)updateRowNumber:(int)theindex;
@end

DetailViewController.m PAGE TOP

#import "Detailviewcontroller.h"
@implementation View
@synthesize dvController;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath
{
if (dvController == nil) {
Detailviewcontroller *aController =
[[Detailviewcontroller alloc]initWithNibName:@"DetailView" bundle:nil];
self.dvController = aController;
        [aController release];
    }
    [[self navigationController] pushViewController:dvController animated:YES];
}
-(void)updateRowNumber:(int)theindex {
rowNumber = theindex + 1;
message.text = [NSString stringWithFormat:@"row %i was clicked", rowNumber];
NSLog(@"view did load row = %d", rowNumber);
}
- (void)viewDidLoad
{
message.text = [NSString stringWithFormat:@"row %i was clicked",rowNumber];
    [super viewDidLoad];
}
- (void)dealloc
{
    [message release];
    [super dealloc];
}
@end

Reference PAGE TOP

http://www.geekylemon.com/WEBPROTECT-xcodetableview.htm

0 Comments Leave a comment

Please login in order to leave a comment.

Newest first
!

Sign-in to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.