// From Beginning iPhone 3 Development: Exploring the iPhone SDK by Mark & LaMarche
// Place this in your viewController.h file
//
// _8_Simple_TableViewController.h
// 08 Simple Table
//
// Created by Amber Weinberg on 7/5/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface _8_Simple_TableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *listData;
}
@property (nonatomic, retain) NSArray *listData;
@end
// in your viewController.m file
//
// _8_Simple_TableViewController.m
// 08 Simple Table
//
// Created by Amber Weinberg on 7/5/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//
#import "_8_Simple_TableViewController.h"
@implementation _8_Simple_TableViewController
@synthesize listData;
- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:@"Sleepy", @"Sneezy", @"Bashful", @"Happy", @"Doc", @"Grumpy", @"Dopey", @"Thorin", @"Dorin", @"Nori", @"Ori", @"Balin", @"Dwalin", @"Fili", @"kili", @"oin", nil];
self.listData = array;
[array release];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
self.listData = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[listData release];
[super dealloc];
}
#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
UIImage *image = [UIImage imageNamed:@"star.png"];
cell.imageView.image = image;
UIImage *imageHighlighted = [UIImage imageNamed:@"star2.png"];
cell.imageView.highlightedImage = imageHighlighted;
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
if (row < 7)
cell.detailTextLabel.text = @"Mr. Disney";
else
cell.detailTextLabel.text = @"Mr. Tolkein";
return cell;
}
@end