// // AIPODataSource.m // TFBrowser // // Created by JB Meyer on 1/20/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "AIPODataSource.h" #import "TFObjects.h" #import "ActorIntegrationProfile.h" #import "Actor.h" #import "IntegrationProfile.h" #import "ActorIntegrationProfileOption.h" @implementation AIPODataSource // return the element at the index - (TFObject *)tfObjectForIndexPath:(NSIndexPath *)indexPath { return [[[TFObjects tfObjects] aipoWithInitialLetter: [[[TFObjects tfObjects] aipoIndexArray ] 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]; } ActorIntegrationProfileOption * aipo = (ActorIntegrationProfileOption *)[self tfObjectForIndexPath:indexPath] ; NSString * text = [[NSString alloc ] initWithFormat:@"%@ %@" , aipo.actorIntegrationProfile.integrationProfile.keyword , aipo.actorIntegrationProfile.actor.keyword] ; NSLog(@"text = %@" , text) ; cell.textLabel.text = text ; [text release]; cell.detailTextLabel.text = [[aipo integrationProfileOption] keyword]; return cell; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // this table has multiple sections. One for each unique character that an element begins with // [A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,R,S,T,U,V,X,Y,Z] // return the count of that array //return [[[PeriodicElements sharedPeriodicElements] elementNameIndexArray] count]; return[[[TFObjects tfObjects] aipoIndexArray] count]; } - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { // returns the array of section titles. There is one entry for each unique character that an element begins with // [A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,R,S,T,U,V,X,Y,Z] //return [[PeriodicElements sharedPeriodicElements] elementNameIndexArray]; return [[TFObjects tfObjects] aipoIndexArray] ; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { return index ; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // the section represents the initial letter of the element // return that letter NSString *initialLetter =[[[TFObjects tfObjects] aipoIndexArray] objectAtIndex:section]; // get the array of elements that begin with that letter NSArray * aipoWithInitialLetter = [[TFObjects tfObjects] aipoWithInitialLetter: initialLetter ] ; // return the count return [ aipoWithInitialLetter count] ; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { // this table has multiple sections. One for each unique character that an element begins with // [A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,R,S,T,U,V,X,Y,Z] // return the letter that represents the requested section // this is actually a delegate method, but we forward the request to the datasource in the view controller return [[[TFObjects tfObjects] aipoIndexArray] objectAtIndex:section]; } @end