Classes/DetailController.m
/* |
Copyright (C) 2015 Apple Inc. All Rights Reserved. |
See LICENSE.txt for this sample’s licensing information |
Abstract: |
Displays details of a single parsed song. |
*/ |
#import "DetailController.h" |
#import "Song.h" |
@interface DetailController () |
@property (nonatomic, readonly, strong) NSDateFormatter *dateFormatter; |
@end |
#pragma mark - |
@implementation DetailController |
- (void)viewDidLoad |
{ |
[super viewDidLoad]; |
_dateFormatter = [[NSDateFormatter alloc] init]; |
(self.dateFormatter).dateStyle = NSDateFormatterMediumStyle; |
(self.dateFormatter).timeStyle = NSDateFormatterNoStyle; |
} |
// When the view appears, update the title and table contents. |
- (void)viewWillAppear:(BOOL)animated { |
[super viewWillAppear:animated]; |
self.title = self.song.title; |
[self.tableView reloadData]; |
} |
#pragma mark - UITableViewDataSource |
- (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section { |
return 4; |
} |
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
static NSString *kCellIdentifier = @"SongDetailCell"; |
UITableViewCell *cell = (UITableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier]; |
if (cell == nil) { |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:kCellIdentifier]; |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
} |
switch (indexPath.row) { |
case 0: { |
cell.textLabel.text = NSLocalizedString(@"album", @"album label"); |
cell.detailTextLabel.text = self.song.album; |
} break; |
case 1: { |
cell.textLabel.text = NSLocalizedString(@"artist", @"artist label"); |
cell.detailTextLabel.text = self.song.artist; |
} break; |
case 2: { |
cell.textLabel.text = NSLocalizedString(@"category", @"category label"); |
cell.detailTextLabel.text = self.song.category; |
} break; |
case 3: { |
cell.textLabel.text = NSLocalizedString(@"released", @"released label"); |
cell.detailTextLabel.text = [self.dateFormatter stringFromDate:self.song.releaseDate]; |
} break; |
} |
return cell; |
} |
- (NSString *)tableView:(UITableView *)tv titleForHeaderInSection:(NSInteger)section { |
return NSLocalizedString(@"Song details:", @"Song details label"); |
} |
@end |
Copyright © 2015 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2015-09-16