-
Notifications
You must be signed in to change notification settings - Fork 872
/
Copy pathSongDetailsController.m
executable file
·99 lines (74 loc) · 2.83 KB
/
SongDetailsController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
Copyright (C) 2017 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
Displays details about a song.
*/
#import "SongDetailsController.h"
#import "Song.h"
#import "Category.h"
@interface SongDetailsController ()
@property (nonatomic, strong) NSDateFormatter *dateFormatter;
@end
#pragma mark -
@implementation SongDetailsController
- (NSDateFormatter *)dateFormatter {
if (_dateFormatter == nil) {
_dateFormatter = [[NSDateFormatter alloc] init];
_dateFormatter.dateStyle = NSDateFormatterMediumStyle;
_dateFormatter.timeStyle = NSDateFormatterNoStyle;
}
return _dateFormatter;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(localeChanged:)
name:NSCurrentLocaleDidChangeNotification
object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSCurrentLocaleDidChangeNotification
object:nil];
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
return 4;
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCellIdentifier = @"SongDetailCell";
UITableViewCell *cell = (UITableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier forIndexPath:indexPath];
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.name;
} 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 *)table titleForHeaderInSection:(NSInteger)section {
return self.song.title;
}
#pragma mark - Locale changes
- (void)localeChanged:(NSNotification *)notif
{
// The user changed the locale (region format) in Settings, so we are notified here to
// update the date format in the table view cells.
//
[self.tableView reloadData];
}
@end