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 )
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.
3 Tell the table how many rows you have.
1Declare the drinks array.(in RootViewController.h )
@interface RootViewController : UITableViewController{(RootViewController.m)
NSMutableArray* drinks;
}
@property (nonatomic, retain) NSMutableArray* drinks;
@end
@synthesize drinks;
-(void)dealloc{
[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];
RootViewController.m
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