// // ActorDataSource.m // TFBrowser // // Created by JB Meyer on 12/29/09. // Copyright 2009 __MyCompanyName__. All rights reserved. // #import "ActorDataSource.h" #import "ActorDataSource.h" #import "TFBrowserAppDelegate.h" #import "TFObject.h" #import "TFObjects.h" #import "Actor.h" @implementation ActorDataSource // return the element at the index - (TFObject *)tfObjectForIndexPath:(NSIndexPath *)indexPath { return [[[TFObjects tfObjects] actorsWithInitialLetter: [[[TFObjects tfObjects] actorsIndexArray] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; } // UITableViewDataSource methods - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"TFObjectTableViewCell"]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TFObjectTableViewCell"] autorelease]; } cell.textLabel.text = [[ self tfObjectForIndexPath:indexPath] keyword]; cell.detailTextLabel.text = [[ self tfObjectForIndexPath:indexPath] name]; return cell ; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { NSLog(@"Number of sections for actors: %d" , [[[TFObjects tfObjects] actorsIndexArray] count] ) ; return[[[TFObjects tfObjects] actorsIndexArray] count]; } - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return [[TFObjects tfObjects] actorsIndexArray] ; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { return index ; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSString *initialLetter =[[[TFObjects tfObjects] actorsIndexArray] objectAtIndex:section]; // get the array of elements that begin with that letter NSArray * actorsWithInitialLetter = [[TFObjects tfObjects] actorsWithInitialLetter: initialLetter ] ; // return the count return [ actorsWithInitialLetter count] ; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [[[TFObjects tfObjects] actorsIndexArray] objectAtIndex:section]; } @end