CatNiP prefinal
Sähköinen nuottikirja, HY-TKTKL-OHTUPROJ KESÄ11
/Users/awniemel/Notepad-SVN/svn/trunk/CatNiP/CatNiP/DetailPopoverController.m
Go to the documentation of this file.
00001 
00006 #import "DetailPopoverController.h"
00007 #import "CatNiPViewController.h"
00008 
00009 @implementation DetailPopoverController
00010 @synthesize composer;
00011 @synthesize composition;
00012 @synthesize metaDataDict;
00013 @synthesize description;
00014 @synthesize sortedKeys;
00015 @synthesize master;
00016 
00023 - (id)initWithStyle:(UITableViewStyle)style masterController:(CatNiPViewController *)controller dictionary:(NSDictionary *)dict
00024 {
00025     self = [super initWithStyle:style];
00026     if (self) {
00027         self.master = controller;
00028         self.metaDataDict = dict;
00029         NSArray *ak = [[NSArray alloc] initWithArray:[dict allKeys]];
00030         self.sortedKeys = [ak sortedArrayUsingSelector:@selector(compare:)];
00031         [ak release];
00032         [self.tableView setAllowsSelection:NO];
00033         }
00034     return self;
00035 }
00036 
00037 - (void)dealloc
00038 {
00039     [composer release];
00040     [composition release];
00041     [metaDataDict release];
00042     [sortedKeys release];
00043     [description release];
00044     [super dealloc];
00045 }
00046 
00047 - (void)didReceiveMemoryWarning
00048 {
00049     // Releases the view if it doesn't have a superview.
00050     [super didReceiveMemoryWarning];
00051 }
00052 
00053 #pragma mark - View lifecycle
00054 
00055 /* initialize everything here */ 
00056 - (void)viewDidLoad
00057 {
00058     /* set same background color as _libTabR */
00059     //self.tableView.backgroundColor = [master.libraryTableViewRight.backgroundColor colorWithAlphaComponent:0.8];
00060     
00061     [super viewDidLoad];
00062     // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
00063     // Oh mister, we don't have a navigationBar!
00064     // self.navigationItem.rightBarButtonItem = self.editButtonItem;
00065 }
00066 
00067 - (void)viewDidUnload
00068 {
00069     [self setTableView:nil];
00070     [self setComposer:nil];
00071     [self setComposition:nil];
00072     [self setDescription:nil];
00073     [self setSortedKeys:nil];
00074     [self setMetaDataDict:nil];
00075     [super viewDidUnload];
00076 }
00077 
00078 /* These are the dummy method's for view appearing, disappearing,etc. see Steve API */
00079 - (void)viewWillAppear:(BOOL)animated
00080 {
00081     [super viewWillAppear:animated];
00082 }
00083 
00084 - (void)viewDidAppear:(BOOL)animated
00085 {
00086     [super viewDidAppear:animated];
00087 }
00088 
00089 - (void)viewWillDisappear:(BOOL)animated
00090 {
00091     [super viewWillDisappear:animated];
00092 }
00093 
00094 - (void)viewDidDisappear:(BOOL)animated
00095 {
00096     [super viewDidDisappear:animated];
00097 }
00098 
00099 /* Nice twist and curl, right? */
00100 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
00101 {
00102     // Return YES for supported orientations
00103         return YES;
00104 }
00105 
00106 #pragma mark - Table view data source
00107 
00115 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
00116 {
00117     return 3 + [[self.metaDataDict allKeys] count];
00118 }
00119 
00129 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
00130 {
00131     return 1;
00132 }
00133 
00141 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
00142 {
00143     UITableViewCell *cell = [self.master tableView:self.tableView createCellWithIdentifier:@"DetailCell"];
00144     cell.textLabel.text = @"";
00145     
00146     switch (indexPath.section) 
00147     {
00148         case 0:
00149             cell.textLabel.text = self.composer;
00150             break;
00151         case 1:
00152             cell.textLabel.text = self.composition;    
00153             break;
00154         case 2:
00155             cell.textLabel.text = self.description; 
00156             break;
00157         default:
00158             [cell.textLabel setText:[self.metaDataDict valueForKey:[self.sortedKeys objectAtIndex:(indexPath.section -3)]]];
00159             break;
00160     }
00161     return cell;
00162 }
00163 
00173 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
00174 {
00175     NSInteger l = 0;
00176     
00177     switch (indexPath.section) 
00178     {
00179         case 0:
00180             l = [self.composer length];
00181             break;
00182         case 1:
00183             l = [self.composition length];
00184             break;
00185         case 2: 
00186             l = [self.description length];
00187             break;
00188         default:
00189             l = [[self.metaDataDict valueForKey:[self.sortedKeys objectAtIndex:(indexPath.section -3)]] length];
00190             //NSLog(@"%d", l);
00191             break;
00192     }
00193     NSInteger height = (((int)(l / 55)+1) * 17) + 20;
00194     return height;    
00195 }
00196 
00205 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
00206 {
00207     return 23;
00208 }
00209 
00220 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
00221 {
00222     UILabel *header = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 50)] autorelease];
00223     header.textAlignment = UITextAlignmentLeft;
00224     header.backgroundColor = [UIColor clearColor];
00225     header.font = [UIFont fontWithName:@"Georgia" size:17.0];
00226     header.text = @"";
00227     
00228     switch (section)
00229     {
00230         case 0:
00231             header.text = @"  Composer";
00232             break;
00233         case 1: 
00234             header.text = @"  Composition";
00235             break;
00236         case 2: 
00237             header.text = @"  Description";
00238             break;
00239         default:
00240             header.text = [@"  " stringByAppendingString:[self.sortedKeys objectAtIndex:(section -3)]];
00241             break;
00242     }
00243        
00244     return header;
00245 }
00246 
00247 /******* Left for later implementation if user wants to edit any info etc. *******/
00248   
00249 /*
00250 // Override to support conditional editing of the table view.
00251 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
00252 {
00253     // Return NO if you do not want the specified item to be editable.
00254     return YES;
00255 }
00256 */
00257 
00258 /*
00259 // Override to support editing the table view.
00260 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
00261 {
00262     if (editingStyle == UITableViewCellEditingStyleDelete) {
00263         // Delete the row from the data source
00264         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
00265     }   
00266     else if (editingStyle == UITableViewCellEditingStyleInsert) {
00267         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
00268     }   
00269 }
00270 */
00271 
00272 #pragma mark - Table view delegate
00273 
00281 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
00282 {
00283     // Navigation logic may go here. Create and push another view controller.
00284     /*
00285      <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
00286      // ...
00287      // Pass the selected object to the new view controller.
00288      [self.navigationController pushViewController:detailViewController animated:YES];
00289      [detailViewController release];
00290      */
00291 }
00292 
00293 @end
 All Classes Files Functions Variables Enumerations Enumerator Properties Defines