// // ActorsDetailsTableViewController.m // TFBrowser // // Created by JB Meyer on 1/9/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "ActorsDetailsTableViewController.h" #import "IntegrationProfileDetailsTableViewController.h" #import "IntegrationProfile.h" #import "Actor.h" #import "ActorIntegrationProfile.h" #import "ActorIntegrationProfileOption.h" #import "TFBrowserAppDelegate.h" @implementation ActorsDetailsTableViewController @synthesize actor , arrayOfIntegrationProfiles ; @synthesize integrationProfileController ; /* - (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 = [actor 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:@"actor.keyword=%@", aip.actor.keyword ]; [fetchRequest setPredicate:predicate]; NSError *error; NSArray *items = [[delegate managedObjectContext] executeFetchRequest:fetchRequest error:&error]; NSLog(@"Number of results :%d" , [items count] ) ; [fetchRequest release]; arrayOfIntegrationProfiles = [[NSMutableArray alloc]init]; NSMutableSet * setOfAIP = [[NSMutableSet alloc] init]; for ( id item in items ) { ActorIntegrationProfile * aip = (ActorIntegrationProfile *) item ; if ( ![setOfAIP containsObject:[[aip integrationProfile] keyword]] ) { [setOfAIP addObject: [[aip integrationProfile] keyword] ]; [arrayOfIntegrationProfiles addObject: [aip integrationProfile] ]; } } } } /* - (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 [arrayOfIntegrationProfiles count] ; } } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if ( section == 0 ) { return @"Actor details" ; } else if ( section == 1 ) { return @"Integration profiles 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 ( actor != nil ) { UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0]; CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT); CGSize labelSize = [actor.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 ( actor != nil ) { NSLog(@"Section %d,row %d",indexPath.section,indexPath.row) ; 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 = actor.keyword; break; case 1: cell.textLabel.text = @"Name"; cell.detailTextLabel.text = actor.name ; break; case 2: cell.textLabel.text = @"Description" ; cell.textLabel.textAlignment = UITextAlignmentLeft ; cell.detailTextLabel.text = actor.tfDescription ; UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:14.0]; cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap ; cell.detailTextLabel.numberOfLines = 1000 ; cell.detailTextLabel.font = cellFont ; break; } } else { static NSString *CellIdentifier = @"Cell2"; cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSLog(@"init cell"); cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:14.0]; cell.textLabel.font = cellFont ; cell.textLabel.text = [[arrayOfIntegrationProfiles objectAtIndex:indexPath.row] keyword]; cell.detailTextLabel.text = [[arrayOfIntegrationProfiles objectAtIndex:indexPath.row] name ]; } } //// return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic may go here. Create and push another view controller. [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (indexPath.section== 1) { IntegrationProfile * profile = [arrayOfIntegrationProfiles objectAtIndex:indexPath.row]; if ( profile != nil ) { IntegrationProfileDetailsTableViewController * myProfileViewController = [[IntegrationProfileDetailsTableViewController alloc] initWithNibName:@"IntegrationProfileDetailsTableViewController" bundle: nil ] ; [self setIntegrationProfileController:myProfileViewController]; self.parentViewController.hidesBottomBarWhenPushed = YES ; [myProfileViewController release ]; integrationProfileController.integrationProfile = profile ; UIBarButtonItem *temporaryBarButtonItem=[[UIBarButtonItem alloc] init]; temporaryBarButtonItem.title=@"Back to actors"; self.navigationItem.backBarButtonItem = temporaryBarButtonItem; [temporaryBarButtonItem release]; // push the element view controller onto the navigation stack to display it [[self navigationController] pushViewController:integrationProfileController animated:YES ]; [profile 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 NO; } */ - (void)dealloc { [actor release]; [arrayOfIntegrationProfiles release]; [super dealloc]; } @end