CatNiP prefinal
Sähköinen nuottikirja, HY-TKTKL-OHTUPROJ KESÄ11
|
00001 00009 #import "PlaylistPopoverController.h" 00010 #import "CatNiPViewController.h" 00011 00012 @implementation PlaylistPopoverController 00013 @synthesize master; 00014 @synthesize score; 00015 00016 - (id)initWithStyle:(UITableViewStyle)style masterController:(CatNiPViewController *)controller andScore:(LocalScoreData *)s 00017 { 00018 self = [super initWithStyle:style]; 00019 if (self) { 00020 self.master = controller; 00021 self.score = s; 00022 } 00023 return self; 00024 } 00025 00026 - (void)dealloc 00027 { 00028 [super dealloc]; 00029 } 00030 00031 - (void)didReceiveMemoryWarning 00032 { 00033 // Releases the view if it doesn't have a superview. 00034 [super didReceiveMemoryWarning]; 00035 00036 // Release any cached data, images, etc that aren't in use. 00037 } 00038 00039 #pragma mark - View lifecycle 00040 00041 - (void)viewDidLoad 00042 { 00043 [super viewDidLoad]; 00044 00045 // Uncomment the following line to preserve selection between presentations. 00046 // self.clearsSelectionOnViewWillAppear = NO; 00047 00048 // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 00049 // self.navigationItem.rightBarButtonItem = self.editButtonItem; 00050 } 00051 00052 - (void)viewDidUnload 00053 { 00054 [super viewDidUnload]; 00055 // Release any retained subviews of the main view. 00056 // e.g. self.myOutlet = nil; 00057 } 00058 00059 - (void)viewWillAppear:(BOOL)animated 00060 { 00061 [super viewWillAppear:animated]; 00062 } 00063 00064 - (void)viewDidAppear:(BOOL)animated 00065 { 00066 [super viewDidAppear:animated]; 00067 } 00068 00069 - (void)viewWillDisappear:(BOOL)animated 00070 { 00071 [super viewWillDisappear:animated]; 00072 } 00073 00074 - (void)viewDidDisappear:(BOOL)animated 00075 { 00076 [super viewDidDisappear:animated]; 00077 } 00078 00079 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 00080 { 00081 // Return YES for supported orientations 00082 return YES; 00083 } 00084 00085 #pragma mark - Table view data source 00086 00087 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 00088 { 00089 return 1; 00090 } 00091 00092 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 00093 { 00094 return [self.master.playlistsDelegateAndDataSource.playlists count]; 00095 } 00096 00097 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 00098 { 00099 UITableViewCell *cell = [self.master tableView:self.tableView createCellWithIdentifier:@"PlaylistCell"]; 00100 cell.textLabel.text = [[self.master.playlistsDelegateAndDataSource.playlists objectAtIndex:indexPath.row] name]; 00101 00102 return cell; 00103 } 00104 00105 /* 00106 // Override to support conditional editing of the table view. 00107 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 00108 { 00109 // Return NO if you do not want the specified item to be editable. 00110 return YES; 00111 } 00112 */ 00113 00114 /* 00115 // Override to support editing the table view. 00116 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 00117 { 00118 if (editingStyle == UITableViewCellEditingStyleDelete) { 00119 // Delete the row from the data source 00120 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 00121 } 00122 else if (editingStyle == UITableViewCellEditingStyleInsert) { 00123 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 00124 } 00125 } 00126 */ 00127 00128 /* 00129 // Override to support rearranging the table view. 00130 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 00131 { 00132 } 00133 */ 00134 00135 /* 00136 // Override to support conditional rearranging of the table view. 00137 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 00138 { 00139 // Return NO if you do not want the item to be re-orderable. 00140 return YES; 00141 } 00142 */ 00143 00144 #pragma mark - Table view delegate 00145 00149 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 00150 { 00151 [[[self.master.playlistsDelegateAndDataSource.playlists objectAtIndex:indexPath.row] scorelist] addObject:self.score]; 00152 [LocalDataHandler savePlaylistsToDefaultFile:self.master.playlistsDelegateAndDataSource.playlists]; 00153 [self.master dismissPlaylistPopover]; 00154 } 00155 00156 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 00157 { 00158 UILabel *header = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 350, 40)] autorelease]; 00159 header.text = @" Add to playlist"; 00160 header.backgroundColor = [UIColor clearColor]; 00161 header.lineBreakMode = UILineBreakModeWordWrap; 00162 header.numberOfLines = 0; 00163 header.font = self.master.defaultFont; 00164 return header; 00165 } 00166 00171 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 00172 { 00173 return 40; 00174 } 00175 00176 @end