Playlist Generator  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
Playlist2/HistoryViewController.m
Go to the documentation of this file.
00001 //
00002 //  HistoryViewController.m
00003 //  Playlist2
00004 //
00005 //  Created by Max Woolf on 27/02/2012.
00006 //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
00007 //
00008 
00009 #import "HistoryViewController.h"
00010 #import "playlist2AppDelegate.h"
00011 #import "EchonestPlaylistParameterViewController.h"
00012 @implementation HistoryViewController
00013 
00014 -(id)customInit
00015 {
00016     playlist2AppDelegate *appDelegate = (playlist2AppDelegate *)[[UIApplication sharedApplication] delegate];
00017     context = appDelegate.managedObjectContext;
00018     return [self init];
00019 }
00020 
00021 - (void)didReceiveMemoryWarning
00022 {
00023     // Releases the view if it doesn't have a superview.
00024     [super didReceiveMemoryWarning];
00025     
00026     // Release any cached data, images, etc that aren't in use.
00027 }
00028 
00029 #pragma mark - Table Delegate
00030 
00031 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
00032 forRowAtIndexPath:(NSIndexPath *)indexPath {
00033     // If row is deleted, remove it from the list.
00034     if (editingStyle == UITableViewCellEditingStyleDelete) {
00035         //remove from local array and persistent storage
00036         [context deleteObject:[playlists objectAtIndex:indexPath.row]];
00037         [context save:nil];
00038         [playlists removeObjectAtIndex:indexPath.row];
00039        
00040         
00041         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
00042         
00043     }
00044 }
00045 
00046 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
00047 {
00048     return 1;
00049 }
00050 
00051 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
00052 {
00053     return [playlists count];
00054 }
00055 
00056 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
00057     static NSString *cellIdentifier = @"Cell";
00058 
00059     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
00060     if (cell == nil) {
00061         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
00062     }
00063 
00064     [cell.textLabel setText:[NSString stringWithFormat:@"%@ - %@", [[playlists objectAtIndex:indexPath.row]valueForKey:@"artist"], [[playlists objectAtIndex:indexPath.row]valueForKey:@"title"] ]];
00065     [cell.detailTextLabel setText:[[playlists objectAtIndex:indexPath.row]valueForKey:@"id"]];
00066     return cell;
00067 }
00068 
00069 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
00070 {
00071     EchonestPlaylistParameterViewController *nextVC = [[EchonestPlaylistParameterViewController alloc] init];
00072     [nextVC setTrackID:[[playlists objectAtIndex:indexPath.row]valueForKey:@"id"]];
00073     nextVC.trackWasIdentified = YES;
00074     [self.navigationController pushViewController:nextVC animated:YES];
00075     [tableView deselectRowAtIndexPath:indexPath animated:YES];
00076 }
00077 
00078 #pragma mark - View lifecycle
00079 
00080 - (void)viewDidLoad
00081 {
00082     [self.navigationController setNavigationBarHidden:NO];
00083     NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
00084     [fetch setEntity:[NSEntityDescription entityForName:@"Track" inManagedObjectContext:context]];
00085     playlists = [NSMutableArray arrayWithArray:[context executeFetchRequest:fetch error:nil]];
00086     [super viewDidLoad];
00087     // Do any additional setup after loading the view from its nib.
00088 }
00089 
00090 - (void)viewDidUnload
00091 {
00092     [super viewDidUnload];
00093     // Release any retained subviews of the main view.
00094     // e.g. self.myOutlet = nil;
00095 }
00096 
00097 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
00098 {
00099     // Return YES for supported orientations
00100     return (interfaceOrientation == UIInterfaceOrientationPortrait);
00101 }
00102 
00103 @end