// // ActorsDetailsTableViewController.m // TFBrowser // // Created by JB Meyer on 1/9/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "IntegrationProfileDetailsTableViewController.h" #import "ActorsDetailsTableViewController.h" #import "IntegrationProfile.h" #import "Actor.h" #import "ActorIntegrationProfile.h" #import "ActorIntegrationProfileOption.h" #import "TFBrowserAppDelegate.h" @implementation IntegrationProfileDetailsTableViewController @synthesize integrationProfile , arrayOfActors ; @synthesize actorController ; /* - (id)initWithStyle:(UITableViewStyle)style { // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. if (self = [super initWithStyle:style]) { } return self; } */ - (void)viewDidLoad { [super viewDidLoad]; TFBrowserAppDelegate * delegate = [[UIApplication sharedApplication] delegate]; NSMutableSet * setOfAIPO = [integrationProfile mutableSetValueForKey:@"actorIntegrationProfile"] ; if ( setOfAIPO != nil ) { NSArray * array = [setOfAIPO allObjects] ; id element = [array objectAtIndex:0]; ActorIntegrationProfile * aip = (ActorIntegrationProfile *) element ; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"ActorIntegrationProfile" inManagedObjectContext:[delegate managedObjectContext]]; [fetchRequest setEntity:entity]; NSLog(@"Keyword :%@" ,[[aip integrationProfile] keyword] ) ; NSPredicate * predicate = [NSPredicate predicateWithFormat:@"integrationProfile.keyword=%@", aip.integrationProfile.keyword ]; [fetchRequest setPredicate:predicate]; NSError *error; NSArray *items = [[delegate managedObjectContext] executeFetchRequest:fetchRequest error:&error]; NSLog(@"Number of results :%d" , [items count] ) ; [fetchRequest release]; arrayOfActors = [[NSMutableArray alloc]init]; NSMutableSet * setOfAIP = [[NSMutableSet alloc] init]; for ( id item in items ) { ActorIntegrationProfile * aip = (ActorIntegrationProfile *) item ; NSLog(@"Actor :%@" , [[aip actor] keyword] ) ; if ( ![setOfAIP containsObject:[[aip actor] keyword]] ) { [setOfAIP addObject: [[aip actor] keyword] ]; [arrayOfActors addObject: [aip actor] ]; } } } } /* - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } */ - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } /* - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } */ /* - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } */ /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (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 { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } #pragma mark Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if ( section == 0 ) return 3; else { return [arrayOfActors count] ; } } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if ( section == 0 ) { return @"Integration profile details" ; } else if ( section == 1 ) { return @"Actors involved" ; } else { return @"" ; } } - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"section :%d, row : %d",indexPath.section , indexPath.row ) ; if ( indexPath.section == 0 ) { if ( indexPath.row == 2 ) { if ( integrationProfile != nil ) { UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:16.0]; CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT); CGSize labelSize = [integrationProfile.tfDescription sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; return labelSize.height + 45; } else { return 45 ; } } else return 45 ; } else { return 45 ; } } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = nil ; // Set up the cell... if ( integrationProfile != nil ) { if ( indexPath.section == 0 ) { static NSString *CellIdentifier = @"Cell1"; cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease]; } switch (indexPath.row) { case 0: cell.textLabel.text = @"Keyword"; cell.detailTextLabel.text = integrationProfile.keyword; break; case 1: cell.textLabel.text = @"Name"; cell.detailTextLabel.text = integrationProfile.name ; break; case 2: cell.textLabel.text = @"Description" ; cell.textLabel.textAlignment = UITextAlignmentLeft ; cell.detailTextLabel.text = integrationProfile.tfDescription ; cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap ; cell.detailTextLabel.numberOfLines = 1000 ; UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:14.0]; cell.detailTextLabel.font = cellFont ; break; } } else { static NSString *CellIdentifier = @"Cell2"; cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:14.0]; cell.textLabel.font = cellFont ; cell.textLabel.text = [[arrayOfActors objectAtIndex:indexPath.row] keyword]; cell.detailTextLabel.text = [[arrayOfActors objectAtIndex:indexPath.row] name]; } } //// return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (indexPath.section== 1) { Actor * actor = [arrayOfActors objectAtIndex:indexPath.row]; if ( actor != nil ) { ActorsDetailsTableViewController * myActorViewController = [[ActorsDetailsTableViewController alloc] initWithNibName:@"ActorsDetailsTableViewController" bundle: nil ] ; [self setActorController:myActorViewController]; self.parentViewController.hidesBottomBarWhenPushed = YES ; [myActorViewController release ]; actorController.actor = actor ; UIBarButtonItem *temporaryBarButtonItem=[[UIBarButtonItem alloc] init]; temporaryBarButtonItem.title=@"Back to int profile"; self.navigationItem.backBarButtonItem = temporaryBarButtonItem; [temporaryBarButtonItem release]; // push the element view controller onto the navigation stack to display it [[self navigationController] pushViewController:actorController animated:YES ]; [actor release]; // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil]; // [self.navigationController pushViewController:anotherViewController]; // [anotherViewController release]; } } } /* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */ /* // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } } */ /* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ - (void)dealloc { [integrationProfile release]; [arrayOfActors release]; [super dealloc]; } @end