Thursday, May 5, 2011

simple Navigationbased tutorial

It’s time to start displaying some drinks. You’ll need to make some modifications to both the RootViewController.h and RootViewController.m files

1Declare the drinks array.(in RootViewController.h )

@interface RootViewController : UITableViewController{
NSMutableArray* drinks;
@property (nonatomic, retain) NSMutableArray* drinks;

@synthesize drinks;

[drinks release];

[super dealloc];


2 Implement and populate the array.(in RootViewController.m)
In RootViewController.m, uncomment and expand the ViewDidLoad methods.
Tell the table how many rows you have.
Populate the table cells.

- (void)viewDidLoad { [super viewDidLoad];
NSMutableArray* tmpArray = [[NSMutableArray alloc]

initWithObjects:@”Firecracker”, @”Lemon Drop”, @”Mojito”,nil];
self.drinks = tmpArray; [tmpArray release];
// Uncomment the following line to display an Edit button in

//the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self. editButtonItem;

3 Tell the table how many rows you have.

//Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.drinks count];
4 Populate the table cells

// Configure the cell.
cell.textLabel.text = [self.drinks objectAtIndex:indexPath.row];

return cell;
Now you’re ready to go. Save it, build and run, and you’ll see the three drinks in your app in the main view.

No comments:

Post a Comment